我正在添加一个 Path 变量
来接收 URL 发送的值。这是我的 Controller 。
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping(value = "/list/{field}", method = RequestMethod.GET)
public void userList(Model model, @PathVariable("field") String field) {
List<Users> userList = userDAO.searchAll();
System.out.println("Condition "+field);
model.addAttribute("userList", userList);
}
请帮我找出这里出了什么问题。
谢谢。
编辑: 还有我是否有机会发送空路径变量 ex:http://localhost:8080/mvcquick/user/list
并返回到相同的方法?
最佳答案
系统正在寻找mvcquick/WEB-INF/jsp/user/list/n.jsp
。
我没有看到这个文件。
请试试这个:
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping(value = "/list/{field}", method = RequestMethod.GET)
public String userList(Model model, @PathVariable("field") String field) {
List<Users> userList = userDAO.searchAll();
System.out.println("Condition "+field);
model.addAttribute("userList", userList);
return "user/list"; // added line. Alos return type to String
}
关于java - 导致 404 的路径变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54033045/