junit
junit
4.11
test
org.mybatis
mybatis
3.4.6
mysql
mysql-connector-java
5.1.38
org.mybatis.generator
mybatis-generator-core
1.3.5
com.itfsw
mybatis-generator-plugin
1.0.5
org.slf4j
slf4j-nop
1.7.25
test
org.junit.jupiter
junit-jupiter-api
5.3.2
compile
com.mchange
c3p0
0.9.5.2
jstl
jstl
1.2
taglibs
standard
1.1.2
org.aspectj
aspectjweaver
1.8.9
org.springframework
spring-aop
4.3.7.RELEASE
org.springframework
spring-aspects
4.3.7.RELEASE
org.springframework
spring-beans
4.3.7.RELEASE
org.springframework
spring-context
4.3.7.RELEASE
org.springframework
spring-core
4.3.7.RELEASE
org.springframework
spring-expression
4.3.7.RELEASE
org.springframework
spring-tx
4.3.7.RELEASE
org.springframework
spring-web
4.3.7.RELEASE
org.springframework
spring-webmvc
4.3.7.RELEASE
org.springframework
spring-test
4.3.7.RELEASE
test
org.springframework
spring-jdbc
4.3.7.RELEASE
org.mybatis
mybatis-spring
1.3.0
com.fasterxml.jackson.core
jackson-core
2.7.3
com.fasterxml.jackson.core
jackson-databind
2.7.3
com.fasterxml.jackson.core
jackson-annotations
2.7.3
2、web.xml
contextConfigLocation
classpath:spring/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
ce
org.springframework.web.filter.CharacterEncodingFilter
true
encoding
UTF-8
ce
/*
ds
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:mvc/SpringMvc.xml
1
ds
/
3、srping.xml
4、springMvc.xml
5、MyBatis逆向生成/gener.xml
6、mybatis.xml
编号
姓名
年龄
性别
工资
津贴
生日
入职时间
上级
部门
操作|
bgcolor="#7fffd4" >
${emp.id}
${emp.name}
${emp.age}
${emp.sex}
${emp.salary}
${emp.bonus}
${emp.leader}
${emp.dept.dname}
删除|
修改
首页
上一页
${i}
下一页
跳转到第页
尾页
1.2、service层
//查询所有
@Override
public List selectAll(PageBean page) {
EmpExample example = new EmpExample();
EmpExample.Criteria criteria = example.createCriteria();
if (page.getName()!=null&&!page.getName().trim().equals("")){
criteria.andNameLike("%"+page.getName()+"%");
}
if (page.getStartBirth()!=null){
criteria.andBirthGreaterThanOrEqualTo(page.getStartBirth());
}
if (page.getEndBirth()!=null){
criteria.andBirthLessThanOrEqualTo(page.getEndBirth());
}
if (page.getDeptId()!=null&&page.getDeptId()!=0){
criteria.andDeptidEqualTo(page.getDeptId());
}
//查询总记录数
int count = (int) empMapper.countByExample(example);
int size=page.getSize();
int totalPage=(count%size==0)?(count/size):(count/size+1);
page.setCount(count);
page.setTotalPage(totalPage);
//分页
int startRow=(page.getCurrPage()-1)*size;
example.limit(startRow,size);
List list = empMapper.selectByExample(example);
for (Emp emp:list){
Dept dept = deptMapper.selectByPrimaryKey(emp.getDeptid());
emp.setDept(dept);
}
return list;
}
1.3、controller层
@Autowired
private IEmpService service;
@RequestMapping("/show")
public ModelAndView show(PageBean page, ModelAndView mav){
List list=service.selectAll(page);
List depts=service.selectDepts();
mav.addObject("list",list);
mav.addObject("depts",depts);
mav.addObject("page",page);
mav.setViewName("show");
return mav;
}
1.2、service层
@Override
public int addEmp(Emp emp) {
return empMapper.insertSelective(emp);
}
1.3、controller层
//实现新增
@RequestMapping("/addEmp")
public String addEmp(Emp emp){
int i=service.addEmp(emp);
return "redirect:/emp/show";
}
//新增成功跳转
@RequestMapping("/add")
public String add(Model model){
List depts = service.selectDepts();
model.addAttribute("depts",depts);
return "add";
}
1.2、service层
@Override//删除
public int deleteById(int id) {
return empMapper.deleteByPrimaryKey(id);
}
@Override//查询单条
public Emp selectById(int id) {
return empMapper.selectByPrimaryKey(id);
}
@Override//修改
public int updateById(Emp emp) {
return empMapper.updateByPrimaryKeySelective(emp);
}
1.3、controller层
//删除
@RequestMapping("/deleteById/{id}")
public String delete(@PathVariable String id) {
int i = service.deleteById(Integer.parseInt(id));
return "redirect:/emp/show";
}
//执行修改
@RequestMapping("/update")
public String updateById(Emp emp){
int i=service.updateById(emp);
return "redirect:/emp/show";
}
//查询单条
@RequestMapping("/selectById/{id}")
public String selectById(@PathVariable String id, Model model){
Emp emp = service.selectById(Integer.parseInt(id));
model.addAttribute("emp",emp);
List depts = service.selectDepts();
model.addAttribute("depts",depts);
return "update";
}