ssm整合2 增删改

前端页面

查询页面

 

编号姓名工资操作
${emp.empno }${emp.ename }${emp.sal }增加编辑删除


增加页面

 

 

编号:
姓名:
工资:


更新页面

 

 

name:sal:


数据层接口

 

 

//数据层的接口
public interface IEmpDao {//数据层的查询方法public ListgetEmps();//根据id查询的方法public ListoneEmps(int n);//增加的方法public int addEmp(Emp e);//删除的方法public int delEmp(int n);//修改的方法public int updateEmp(Emp e);
}


mapper映射文件

 

 

insert into emp(empno,ename,sal) values(#{empno},#{ename},#{sal})delete from emp where empno=#{empno}update emp set ename=#{ename},sal=#{sal} where empno=#{empno}

业务层接口

 

 

//业务层接口
public interface IEmpService {public List getEmps();//增加的方法public int addEmp(Emp e);//删除的方法public int delEmp(int n);//根据id查询的方法public ListoneEmps(int n);//修改的方法public int updateEmp(Emp e);
}


业务层实现类

 

 

package aaa.service.impl;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;import aaa.dao.IEmpDao;
import aaa.entity.Emp;
import aaa.service.IEmpService;
@Component
public class EmpService implements IEmpService {@Resourceprivate IEmpDao empDao;public List getEmps() {return empDao.getEmps();}public int addEmp(Emp e) {return empDao.addEmp(e);}public int delEmp(int n) {return empDao.delEmp(n);}public List oneEmps(int n) {return empDao.oneEmps(n);}public int updateEmp(Emp e) {return empDao.updateEmp(e);}}


控制器代码

 

 

package aaa.controller;import java.util.List;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import aaa.entity.Emp;
import aaa.service.IEmpService;@Controller
@RequestMapping("/emp")
public class EmpController {//byName注入@Resourceprivate IEmpService service;@RequestMapping("/list")public String getList(Model model){List emps = service.getEmps();model.addAttribute("emps",emps);return "list";}@RequestMapping("/toAddEmp")public String toAddEmp(){return "AddEmp";}@RequestMapping("/AddEmp")public String AddEmp(Emp e){service.addEmp(e);return "redirect:list"; }@RequestMapping("/delEmp")public String delEmp(HttpServletRequest req){int n = Integer.parseInt(req.getParameter("empno"));service.delEmp(n);return "redirect:list"; }@RequestMapping("/updateEmp")public String updateEmp(HttpServletRequest req,Model model){int n = Integer.parseInt(req.getParameter("empno"));List emps = service.oneEmps(n);model.addAttribute("emps",emps);return "update";}@RequestMapping("/updateEmps")public String updateEmps(Emp e){service.updateEmp(e);return "redirect:list"; }}

 

 

 

 

 

 

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部