Spring mvc SpringMVC,如果RequestMapping中提到的单词与URL中的匹配,则调用Controller
如果执行的URL包含相应控制器的@RequestMapping中提到的单词,是否可以调用控制器 这是我的密码Spring mvc SpringMVC,如果RequestMapping中提到的单词与URL中的匹配,则调用Controller,spring-mvc,Spring Mvc,如果执行的URL包含相应控制器的@RequestMapping中提到的单词,是否可以调用控制器 这是我的密码 @Controller @RequestMapping({"/employee","/nonemployee","/temp"}) public class EmployeeController { @Autowired EmployeeService service; @RequestMapping("/add") public ModelAndView e
@Controller
@RequestMapping({"/employee","/nonemployee","/temp"})
public class EmployeeController {
@Autowired
EmployeeService service;
@RequestMapping("/add")
public ModelAndView employee() {
ModelAndView modelAndView = new ModelAndView("emp/add", "command", new Employee());
return modelAndView;
}
@RequestMapping("/employees")
public ModelAndView getEmployeeList() {
ModelAndView modelAndView = new ModelAndView("/emp/employees", "list", service.getEmployeeList());
return modelAndView;
}
@RequestMapping(value = "/create")
public String createEmployee(@ModelAttribute Employee employee, ModelMap model) {
service.newEmployee(employee);
model.addAttribute("name", employee.getName());
model.addAttribute("age", employee.getAge());
model.addAttribute("id", employee.getId());
return "/emp/create";
}
}
将上述代码与@RequestMapping({”/employee“,“/nonemployee“,“/temp”})
和@RequestMapping(“/employees”)
一起使用,我们可以调用以下URL来列出值:
http://localhost:8080/Spring/employee/employees
http://localhost:8080/Spring/nonemployee/employees
http://localhost:8080/Spring/temp/employees
getEmployeeList()
)返回值列表,但不将多个或所有值传递给RequestMapping注释:
http://localhost:8080/Spring/employee/employees
http://localhost:8080/Spring/nonemployee/employees
http://localhost:8080/Spring/temp/employees
http://localhost:8080/Spring/exempt/employees
http://localhost:8080/Spring/attempt/employees
将请求映射更改为-
@RequestMapping("/*emp*")
这应该适用于您想要执行的操作。您可以尝试指定一个正则表达式,看看它是否有效。