开发步骤
第一步:配置springmvc.xml
<mvc:annotation-driven/>
<context:component-scan base-package="控制器的包路径"/>
第二步:写控制器
@Controller
@RequestMapping
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.ssm.controller; 2 3 import java.util.List; 4 5 import javax.annotation.Resource; 6 7 import org.springframework.stereotype.Controller; 8 import org.springframework.ui.Model; 9 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestParam; 11 12 import com.ssm.pojo.User; 13 import com.ssm.service.user.UserService; 14 15 @Controller 16 @RequestMapping("/sys/user") 17 public class UserController { 18 19 @Resource 20 private UserService userService; 21 22 @RequestMapping("/qry") 23 public String findUserByNR(@RequestParam("name")String name,@RequestParam("roleId")String roleId,Model model){ 24 List<User> users=userService.findUserByNR(name, roleId); 25 model.addAttribute("users", users); 26 return "index"; 27 } 28 29 public UserService getUserService() { 30 return userService; 31 } 32 public void setUserService(UserService userService) { 33 this.userService = userService; 34 } 35 }
第三步:测试