@Controller public class UnitConntrol { @Autowired UnitService unitService; @RequestMapping(value = "/findUintId/{id}",method = RequestMethod.GET) public Object findUnitId(@PathVariable("id") Integer id, Model model){ System.out.println("jinru"); Unit unit = unitService.selectByPrimaryKey(id); System.out.println(unit.getName()); model.addAttribute(unit); return "unitview"; } /** ——第二種方法--- @RequestMapping(value = "/findUintId/{id}",method = RequestMethod.GET) public @ResponseBody ModelAndView findUnitId(@PathVariable("id") Integer id, Model model){ System.out.println("jinru"); Unit unit = unitService.selectByPrimaryKey(id); System.out.println(unit.getName()); model.addAttribute(unit); return new ModelAndView("unitview.html"); } */ }
2.Control包中的類若是加入的註解爲@RestController{RestController = ResponseBody + Controller}html
@RestController public class UserControl { @Autowired UserService userService; //根據ID對user查看 @RequestMapping(value = "/findByUserid/{id}",method = RequestMethod.GET) public ModelAndView findByUserid(@PathVariable("id")Integer id, Model model){ System.out.println(「running findByUserid"); User user = userService.findByUserid(id); System.out.println(user.getName()); model.addAttribute("user",user); return new ModelAndView("userview.html"); } }