一\前期配置
https://blog.csdn.net/lavendeyan/article/details/106040694
二\代码编写
1\目录以及流程
1)先在bean中编写实体类,其次在dao中编写需要实现的方法名,然后在mapper中的xml编写对数据库进行操作的sql语句。
2)在service中,先在接口中编写需要实现的方法名,然后在impl中实现接口中的方法,最后在web.controller中编写对方法执行的控制。
2\Department.java
1、将数据库中对应的字段在实体类中声明
2、创建get|set方法(快捷键:alt+insert 或者 连按shift搜索getset)
整体代码:
package com.bs.mstp.mstp01.bean;
import java.util.Date;
public class Department {
private Long id;
private String name;
private String director;
private String address;
private String tel;
private Date foundtime;
...(get|set方法)
}
3\DepartmentMapper.java
整体代码:
package com.bs.mstp.mstp01.dao;
import com.bs.mstp.mstp01.bean.Department;
import java.util.List;
public interface DepartmentMapper {
/**
* private Long id;
* private String name;
* private String director;
* private String address;
* private String tel;
* private Date foundtime;
* */
List<Department> findAll();//查询所有
Department findById(long id);//根据id查询
List<Department> query(Department department);//模糊查询-多条件复合查询-
void insert(Department department);//增加
void update(Department department);//修改
void deleteById(long id);//删除
}
4\DepartmentMapper.xml
整体代码:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
private Long id;
private String name;
private String director;
private String address;
private String tel;
private Date foundtime;