Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Thymeleaf弹簧验证不';t显示_Spring Boot_Thymeleaf_Spring Validator - Fatal编程技术网

Spring boot Thymeleaf弹簧验证不';t显示

Spring boot Thymeleaf弹簧验证不';t显示,spring-boot,thymeleaf,spring-validator,Spring Boot,Thymeleaf,Spring Validator,我试图在HTML上显示从控制器获得的错误消息,但我没有看到显示的消息 我打印了${#fields.hasrerrors('name')},我看到它给了我false 我调试了我的代码,发现有一个错误 com.gurnah.controller.ProductController:产品大小必须介于2和150之间 我的HTML <form th:object="${product}" th:action="@{/product/save}" method="post"> .....

我试图在HTML上显示从控制器获得的错误消息,但我没有看到显示的消息

我打印了${#fields.hasrerrors('name')},我看到它给了我false

我调试了我的代码,发现有一个错误

com.gurnah.controller.ProductController:产品大小必须介于2和150之间

我的HTML

<form th:object="${product}" th:action="@{/product/save}" method="post">
.....
    <div class="form-group" 
               th:classappend="${#fields.hasErrors('name')}? 'has-error'">
    <label th:for="name" class="col-form-label">Product Name:</label> 
    <input type="text" class="form-control" th:field="*{name}" />
    <span th:if="${#fields.hasErrors('name')}" 
          th:errors="*{name}" 
          th:class="help-block">Title Errors</span>
    </div>

.....
产品名称:
标题错误

什么是#字段?#字段是内置函数还是我错了?对不起,是的,我被弄糊涂了:-)但另一个问题:bindingResult来自哪里?我首先尝试使用BindResult,但不起作用,所以我使用了错误,它的工作原理与Bind Result相同要清楚的是,您可以在日志文件中看到错误?什么是#fields?#fields是内置函数还是我错了?对不起,是的,我被弄糊涂了:-)但是另一个问题:bindingResult来自哪里?我首先尝试使用BindResult,但它不起作用,所以我使用了错误,它的工作原理与Bind result相同。要清楚,您可以在日志文件中看到错误吗?
@Entity
public class Product {

    @Id
    @Column(name = "ProdID", updatable = false, nullable = false)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_generator")
    @SequenceGenerator(name="product_generator", sequenceName = "zseq_product", allocationSize=1)
    private int ProdID;

    @NotNull(message = "Field Product cannot be empty")
//  @NotEmpty(message = "Field Product cannot be empty")
    @Size(min = 2, max = 150)
    private String name;

    private String prodDesc;
<form th:object="${product}" th:action="@{/product/save}" method="post">
.....
    <div class="form-group" 
               th:classappend="${#fields.hasErrors('name')}? 'has-error'">
    <label th:for="name" class="col-form-label">Product Name:</label> 
    <input type="text" class="form-control" th:field="*{name}" />
    <span th:if="${#fields.hasErrors('name')}" 
          th:errors="*{name}" 
          th:class="help-block">Title Errors</span>
    </div>