Back-end structure: com.lm.ssm.action-> empAction.java

                  com.lm.ssm.dao->EmpDao.java

                  com.lm.ssm.service->EmpService.java

                  com.lm.ssm.vo->Emp.java

                                             EmpMapper.xml

1) vo layer code

Emp.java

    private Integer id;

private String name;

private Double sal;

private String sex;

private Date date;

Parameterless and parameterless constructors, set/get omitted

      

   EmpMapper.xml

****








eid,ename,esal,esex,date

insert into emps(eid,ename,esal,esex,date) values(#{id},#{name},#{sal},#{sex},#{date})
select *
–> from emps
select
from emps where eid=#{id,jdbcType=INTEGER}

UPDATE emps


ename=#{name,jdbcType=VARCHAR},


esal=#{sal,jdbcType=DOUBLE},


esex=#{sex,jdbcType=VARCHAR},


date=#{date,jdbcType=TIMESTAMP},

WHERE eid=#{id,jdbcType=INTEGER}


DELETE FROM emps WHERE eid=#{id,jdbcType=INTEGER}


** public void add(Emp Emp); ** public void add(Emp Emp); public List

listAll(); public Emp findById(Integer id); public void update(Emp emp); public void delete(Integer id);

3) Service layer codeEmpService.java

@Component public class EmpService { @Autowired private EmpDao empDao; /** * Register employee */ @Transactional public void register(Emp Emp) throws Exception{empdao.add (Emp); } public List

listAll(){ return empDao.listAll(); } public Emp findById(Integer id){ return empDao.findById(id); } @Transactional public void update(Emp emp){ empDao.update(emp); } @Transactional public void delete(Integer id){ empDao.delete(id); }} 4) Empaction.java

@Component @RequestMapping(value=”/emp”) public class EmpAction { @Autowired private EmpService empService; @RequestMapping(value=”/emps”,method=RequestMethod.POST) public String registerMethod(Emp emp) throws Exception{ emp.setDate(new Timestamp(new Date().getTime())); empService.register(emp); return “redirect:/emp/emps”; } //forward:/ @RequestMapping(value=”/emps”,method=RequestMethod.GET) public String lists(Map

> map){ List

listAll = empService.listAll(); map.put(“listAll”, listAll); return “list”; } @RequestMapping(value=”/emps/{id}”,method=RequestMethod.GET) public String updatelist(@PathVariable(“id”) Integer id,Map

map){ Emp findById = empService.findById(id); map.put(“emps”, findById); return “updatelist”; } @RequestMapping(value=”/emps”,method=RequestMethod.PUT) public String updatesave(Emp emp){ try { empService.update(emp); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return “redirect:/emp/emps”; } @RequestMapping(value=”/emps/{id}”,method=RequestMethod.DELETE) public String delete(@PathVariable(“id”) Integer id){ empService.delete(id); return “redirect:/emp/emp1”; }} to be continued! ————————————————————————————————
,object>

,list