Servlet+Mybatis+Jsp实现用户的增删改查
1、Mysql数据库建表
CREATE DATABASE flower DEFAULT CHARACTER SET utf8;
USE flower
CREATE TABLE test(
id int(10) PRIMARY KEY NOT NULL AUTO_INCREMENT COMMENT '编号',
name VARCHAR(30) NOT NULL COMMENT '花名',
price int(10) NOT NULL COMMENT '价格',
producter VARCHAR(30) NOT NULL COMMENT '生产地'
)
INSERT INTO test VALUES(DEFAULT, '兰花',5,'杭州');
INSERT INTO test VALUES(DEFAULT, '玫瑰花',5,'上海');
INSERT INTO test VALUES(DEFAULT, '百合',5,'北京');
2、在Idea中建立Web项目,WEB-INF下建立lib放入jar包,也就是JDBC数据库连接、jstl,小练习总体如下

3、建立pojo类
package com.pojo;
/**
* @Auther:jiaxuan
* @Date: 2019/3/20 0020 21:27
* @Description:
*/
public class Flower {
private int id;
private String name;
private int price;
private String producter;
public Flower() {
}
public Flower(int id, String name, int price, String producter) {
this.id = id;
this.name = name;
this.price = price;
this.producter = producter;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getPrice(){
return price;
}
public void setPrice(int price){
this.price = price;
}
public String getProducter(){
return producter;
}
public void setProducter(String producter){
this.producter = producter;
}
}
4、建立Dao层及其实现类
package com.dao;
import com.pojo.Flower;
import java.util.List;
/**
* @Auther:jiaxuan
* @Date: 2019/3/20 0020 21:33
* @Description:
*/
public interface FlowerDao {
List<Flower> selectAll();
int ins

本文介绍了如何使用Servlet、Mybatis和Jsp来实现用户查询和新增功能。首先在Mysql数据库中创建用户表,接着在IntelliJ IDEA中搭建Web项目,配置好JDBC和相关库。接着创建POJO类、Dao接口及其Impl实现,Service层和服务实现,最后是Web层的Controller和展示页面(index.jsp、add.jsp)。

3万+

被折叠的 条评论
为什么被折叠?



