java - 导致 404 的路径变量

标签 java path-variables


我正在添加一个 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);
    }

但是我遇到了 404 错误。 browser screenshot

这是我的 jsp 文件夹结构。 JSP folder structure

请帮我找出这里出了什么问题。
谢谢。


编辑: 还有我是否有机会发送空路径变量 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/

相关文章:

java - 从 java 捕获 ssh 命令输出

java - 无法在 native 扫描仪上读取文件两次

java - 粒子 Action 非常快 libgdx java

cmd - 在没有 PATH 变量的 cmd 中的任何位置运行 .exe

java - @PathVariable ("ownerId") String theOwner 和@PathVariable String theOwner 的区别

node.js - Sails.js - PATH 变量 - 无法识别 sails 命令

java - 即使应用程序未运行,也会显示警报对话框

Java - .class 文件中的 package 语句是否被删除?

unix - 如何在 shell 脚本中操作 $PATH 元素?

Spring MVC : how to indicate whether a path variable is required or not?