Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/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
Java ThymileAF th:字段在窗体显示中给出错误信息_Java_Spring Boot_Thymeleaf - Fatal编程技术网

Java ThymileAF th:字段在窗体显示中给出错误信息

Java ThymileAF th:字段在窗体显示中给出错误信息,java,spring-boot,thymeleaf,Java,Spring Boot,Thymeleaf,表单实际显示时没有th:field属性,但在添加th:field属性时停止。我不知道为什么它总是指向我在表单字段中使用的th:字段 @Data @AllArgsConstructor @NoArgsConstructor @Entity public class Sections { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Integer Id; @NotNull

表单实际显示时没有th:field属性,但在添加th:field属性时停止。我不知道为什么它总是指向我在表单字段中使用的th:字段

    @Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Sections {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Integer Id;
    
    @NotNull
    @Column(unique = true)
    String sectionName;

}
服务等级

    @Service
public class SectionService {

    @Autowired
    SectionRepository sectionRepository;
    
    public void addNewSection(Sections section) {
    
        sectionRepository.save(section);
        
    }

    public List<Sections> listAllSections() {
        
        return sectionRepository.findAll();
    }


}
html文件

<body>

    <div layout:fragment="content" class="main-container">
        <div class="text-center border shadow">
            <h2>Academics</h2>
        </div>
        <br>
        <div class="Form p-3 border" >
            <div class="row no-gutters">
                <div class="col-md-4 col-lg-4">
                    <form method="post" th:object="${sectionObject}" th:action="@{/sections}"
                        class="form1 border shadow">
                        <div class="form-row">
                            <div class="form-group">
                                    <label for="sectionName">Section Name</label> <input type="text"
                                        class="form-control"  
                                        placeholder="Enter Section" th:field="*{sectionName}" >
                                    
                            </div>
                            
                        </div>
                        <button type="submit" class="btn btn-primary">Add</button>
                    </form>
                </div>

                <div class="col-md-8 col-lg-8">
                <form method="post" th:object="${sectionObject}" th:action="@{/sections}" class="form2 border shadow">
已写入部分错误代码

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'sectionName' of bean class [java.util.ArrayList]: Bean property 'sectionName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:627)
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:617)
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:158)
    at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903)
    at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227)
    at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174)
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
    ... 112 more
原因:org.springframework.beans.NotReadablePropertyException:bean类[java.util.ArrayList]的无效属性'sectionName':bean属性'sectionName'不可读或具有无效的getter方法:getter的返回类型与setter的参数类型匹配吗?
位于org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:627)
位于org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:617)
位于org.springframework.web.servlet.support.BindStatus。(BindStatus.java:158)
位于org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903)
位于org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227)
位于org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedPression(FieldUtils.java:306)
位于org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253)
位于org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227)
位于org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174)
位于org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
... 112多

您的控制器对两个不同的模型属性使用相同的键:

model.addAttribute("sectionObject", new Sections());
model.addAttribute("sectionObject", sectionService.listAllSections());
我建议在所有章节的列表中使用不同的名称。例如:

model.addAttribute("sectionObject", new Sections());
model.addAttribute("allSections", sectionService.listAllSections());
并更新您的ThymileAF模板以使用新名称:

<tr th:each="mySections:${allSections}">

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'sectionName' of bean class [java.util.ArrayList]: Bean property 'sectionName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:627)
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:617)
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:158)
    at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903)
    at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253)
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227)
    at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174)
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
    ... 112 more
model.addAttribute("sectionObject", new Sections());
model.addAttribute("sectionObject", sectionService.listAllSections());
model.addAttribute("sectionObject", new Sections());
model.addAttribute("allSections", sectionService.listAllSections());
<tr th:each="mySections:${allSections}">