日期:2014-05-16  浏览次数:20841 次

Spring3+mybatis+mysql整合详解(五)

下面来看java代码:

1、Control层代码:

?

Java代码 复制代码
  1. package?com.hl.usersmanager.controller; ??
  2. ??
  3. import?java.util.List; ??
  4. ??
  5. import?org.springframework.beans.factory.annotation.Autowired; ??
  6. import?org.springframework.stereotype.Controller; ??
  7. import?org.springframework.ui.ModelMap; ??
  8. import?org.springframework.web.bind.annotation.RequestMapping; ??
  9. ??
  10. import?com.hl.usersmanager.model.Users; ??
  11. import?com.hl.usersmanager.service.IUserService; ??
  12. ??
  13. @Controller??
  14. public?class?UserController?{ ??
  15. //??使用注解实现自动装配?不需要再写get?set方法以及在context中配置bean ??
  16. ????@Autowired??
  17. ????private?IUserService?userService; ??
  18. ??
  19. ????@RequestMapping(value?=?"findUserByName.do") ??
  20. ????public?String?findUserByName(String?name,ModelMap?model)?{ ??
  21. ????????Users?users?=?userService.findUserByName(name); ??
  22. ????????model.addAttribute("userPhone",users.getPhone()); ??
  23. ????????System.out.println("userPhone:"?+?users.getPhone()); ??
  24. ????????return?"showUser"; ??
  25. ????} ??
  26. ???? ??
  27. ????…… ??
  28. }??
package com.hl.usersmanager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.s