数据库表 dept(id,name)
用 分层开发的思路 进行数据的增删改
在pom.xml 增加
<dependencies> <!--增加依赖--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.30</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies>
编写实体层
package entity;
public class Dept {
private int id;
private String name;
public Dept() {
}
public Dept(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "Dept{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
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;
}
}
编写业务接口
package service;
import entity.Dept;
import java.sql.SQLException;
import java.util.List;
public interface IDeptService {
/**
* 查询全部
* @return 数据库表 dept的全部数据
*/
List<Dept> queryAll();
/**
* 按照编号删除 部门信息
* @param id 部门编号
* @return 受影响的行数, >0 执行成功, 否则 失败
*/
int delById(int id);
/**
* 按照编号修