执行处理器' org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor'

时间:2017-10-08 22:33:38

标签: spring spring-mvc spring-boot data-binding thymeleaf

尝试更改包含私有String名称的模型类中的值,并且我想在HTML页面中使用Thymeleaf更改名称,然后在另一个url响应主体中查看更改。

当我尝试访问localhost中的(" / myname")页面时,我收到了错误消息: 执行处理器期间出错&org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor'

这是我的模特:

public class Name {

    public String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

这是我的控制器

@Controller
public class MainController {

    @RequestMapping("/name")
    @ResponseBody 
    public String showName() {
        Name myname = new Name();
        return myname.getName();
    }

    @RequestMapping("/myname")
    public String setName() {
        return "myname";
    }

    @RequestMapping(value = "myname", method = RequestMethod.POST)
    public String showName(@ModelAttribute Name iko, BindingResult errors, Model model) {
        return "name";
    }   
}

这是我的html百里香页面: myname.html

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="ISO-8859-1"/>
    <title>Insert title here</title>
</head>
<body>
<form action="#" th:action="@{/myname}" th:object="${iko}" method="post">
    <label>Enter the name</label><br/>
    <input type="text" th:field="*{name}"/>
    <button type="submit">SUBMIT</button>
</form>
</body>
</html>

0 个答案:

没有答案