首页 > 解决方案 > Spring Boot 2.0.5 是否不运行请求参数

问题描述

我正在尝试学习 spring boot 2.0 的基础知识,当我尝试将待办事项添加到我的待办事项列表应用程序时,我不断收到白标签错误。Spring Boot 2.0 是否仍然使用请求参数或已弃用?因为即使我尝试删除一个待办事项,我仍然会收到一个白标签错误,说没有传递 id。

我的待办事项控制器:

public class TodoController {

    @Autowired
    TodoService service;

    @RequestMapping(value = "/list-todos", method = RequestMethod.GET)
    public String showTodos(ModelMap modelMap) {
        String name = (String) modelMap.get("name");
        modelMap.put("todos", service.retrieveTodos(name));
        return "list-todos";
    }


    @RequestMapping(value = "/add-todo", method = RequestMethod.GET)
    public String showAddTodoPage(ModelMap model) {
        return "todo";
    }

    @RequestMapping(value = "/add-todo", method = RequestMethod.POST)
    public String addTodo(ModelMap model, @RequestParam String desc) {
        service.addTodo((String) model.get("name"), desc, new Date(), false);
        return "redirect:/list-todos";
    }

    @RequestMapping(value = "/delete-todo", method = RequestMethod.GET)
    public String deleteTodo(@RequestParam("id") int id, ModelMap model) {
        model.put("id", id);
        service.deleteTodo(id);
        return "redirect:/list-todos";
    }
}

我的待办事项 JSP:

<html>
<head>
    <title>add-todo</title>
</head>
<body>
<h1>Add Todo Page for ${name}</h1>

<form action="Post" method="post">
    <input type="text" name="desc">
    <br>
    <input type="submit">
</form>
</body>
</html>

标签: javajspspring-boot

解决方案


推荐阅读