首页 > 解决方案 > Thymleaf -> 执行处理器“org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”时出错

问题描述

我正在尝试获取 add-journeyFooOrder 视图并且无法执行(获取视图说 - Whitelabel Error Page)所以请帮助我,让我知道我在这里做错了什么以及为什么。提前致谢

所以当我第一次点击localhost:8080时,我可以从那里获取index.html我点击链接添加订单然后我应该被重定向到我收到错误的add-journeyFoodOrder.html视图(请查看控制器代码这将更加清晰)。错误日志如下:

org.thymeleaf.exceptions.TemplateProcessingException:在 org.thymeleaf.processor.element.AbstractAttributeTagProcessor 处执行处理器“org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”(模板:“add-journeyFoodOrder” - 第 19 行,第 29 列)时出错。 doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0 .12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]在 org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.engine.StandaloneElementTag.beHandled(StandaloneElementTag.java:228) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf。 engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:661) ~[thymeleaf -3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org .thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:366) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1393) ~[spring-webmvc-5.3 .6.jar:5.3.6] 在 org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1138) ~[spring-webmvc-5.3.6.jar:5.3.6] 在 org.springframework.web .servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1077) ~[spring-webmvc-5.3.6.jar:5.3.6] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962) ~[ spring-webmvc-5.3.6.jar:5.3.6] 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.6.jar:5.3.6] 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.6.jar:5.3.6] at javax.servlet.http。HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.45.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring -webmvc-5.3.6.jar:5.3.6] 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.45.jar:4.0.FR] 在 org .apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. java:162) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket -9.0.45.jar:9.0.45] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org .apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java :100) ~[spring-web-5.3.6.jar:5.3.6] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.6.jar: 5.3.6] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org.apache.catalina.core。 ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring -web-5.3.6.jar:5.3.6] 在 org.springframework.web.filter.OncePerRequestFilter。doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.6.jar:5.3.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core -9.0.45.jar:9.0.45] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org .springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.6.jar:5.3.6] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 119) ~[spring-web-5.3.6.jar:5.3.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.45.jar :9.0.45] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)~[tomcat-embed-core-9.0.45 .jar:9.0.45] 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org.apache.catalina .authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.45.jar :9.0.45] 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org.apache.catalina.connector .CoyoteAdapter。服务(CoyoteAdapter.java:357)~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)~[tomcat-embed -core-9.0.45.jar:9.0.45] 在 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org .apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) ~[tomcat-embed-core-9.0.45.jar:9.0.45] 在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor。 doRun(NioEndpoint.java:1707) ~[tomcat-embed-core-9.0.45.jar:9.0.45] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat -embed-core-9.0.45.jar:9.0.45] 在 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na] 在 java.base/java.util 。同时。ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0 .45.jar:9.0.45] 在 java.base/java.lang.Thread.run(Thread.java:832) ~[na:na] 原因:java.lang.IllegalStateException:BindingResult 和普通目标对象都不是bean 名称“journeyFoodOrder”可作为请求属性在 org.springframework.springframework.web.servlet.support.BindStatus.(BindStatus.java:153) ~[spring-webmvc-5.3.6.jar:5.3.6] 在 org.springframework。 web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.3.6.jar:5.3.6] at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java :227)〜[百里香弹簧5-3.0.12.RELEASE.jar:3.0.12。RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.util。 FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~ [thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.12.RELEASE。 jar:3.0.12.RELEASE] 在 org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]306) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.12 .RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]在 org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.processor.element.AbstractAttributeTagProcessor。 doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]306) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.12 .RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]在 org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.processor.element.AbstractAttributeTagProcessor。 doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.processor。 AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~ [百里香-3.0.12.RELEASE.jar:3.0.12.RELEASE]RELEASE] 在 org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.processor。 AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~ [百里香-3.0.12.RELEASE.jar:3.0.12.RELEASE]AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]

查看 add-journeyFoodOrder.html

        <div class="col-md-6">
            <form action="#" th:action="@{/addJourneyFoodOrder}" th:object="${journeyFoodOrder}" method="post">
                <label for="nameOfCenter">Name of Center</label>
                <input type="text" th:field="*{nameOfCenter}" placeholder="Name of Center">
                <span th:if="${#fields.hasErrors('nameOfCenter')}" th:errors="*{nameOfCenter}"></span>
                
                <label for="nameOfGuide">Name of Guide</label>
                <input type="text" th:field="*{nameOfGuide}" placeholder="Name of Guide">
                <span th:if="${#fields.hasErrors('nameOfGuide')}" th:errors="*{nameOfGuide}"></span>
                
                <label for="headCount">Head count</label>
                <input type="number" th:field="*{headCount}" placeholder="Head count">
                <span th:if="${#fields.hasErrors('headCount')}" th:errors="*{headCount}"></span>
                
                <label for="dateOfJourney">Mobile No Of Guide</label>
                <input type="text" th:field="*{contactNoOfGuide}" placeholder="Mobile No Of Guide">
                <span th:if="${#fields.hasErrors('contactNoOfGuide')}" th:errors="*{contactNoOfGuide}"></span>
                
                <label for="dateOfDeparture">Date of departure</label>
                <input type="text" th:field="*{dateOfDeparture}" placeholder="Date Of departure">
                <span th:if="${#fields.hasErrors('dateOfDeparture')}" th:errors="*{dateOfDeparture}"></span>
                
                <label for="mealRetrievalTime">Meal retrieval time</label>
                <input type="text" th:field="*{mealRetrievalTime}" placeholder="Mobile No Of Guide">
                <span th:if="${#fields.hasErrors('mealRetrievalTime')}" th:errors="*{mealRetrievalTime}"></span>
                
                <input type="submit" value="Add Order">   
            </form>
        </div>

JourneyFoodOrderController 类

@Controller
public class JourneyFoodOrderController {
    
    private final JourneyFoodOrderRepository journeyFoodOrderRepository;

    @Autowired
    public JourneyFoodOrderController(JourneyFoodOrderRepository journeyFoodOrderRepository) {
        // TODO Auto-generated constructor stub
        this.journeyFoodOrderRepository = journeyFoodOrderRepository;
    }
    
    @GetMapping("/signup")
    public String showSignUpForm(JourneyFoodOrderRepository journeyFoodOrderRepository) {
        return "add-journeyFoodOrder";
    }
    
    @PostMapping("/addJourneyFoodOrder")
    public String addJourneyFoodOrder(@Valid @ModelAttribute(value="journeyFoodOrder") JourneyFoodOrder journeyFoodOrder, BindingResult result, Model model) {
        if (result.hasErrors()) {
            return "add-journeyFoodOrder";
        }
        model.addAttribute("journeyFoodOrder", journeyFoodOrder);
        journeyFoodOrderRepository.save(journeyFoodOrder);
        return "redirect:/index";
    }
    
    @GetMapping("/index")
    public String showJourneyFoodOrderList(Model model) {
        model.addAttribute("journeyFoodOrders", journeyFoodOrderRepository.findAll());
        return "index";
    }
}

POJO 是

@Entity
public class JourneyFoodOrder{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Override
    public String toString() {
        return "JourneyFoodOrder [id=" + id + ", nameOfCenter=" + nameOfCenter + ", nameOfGuide=" + nameOfGuide
                + ", headCount=" + headCount + ", contactNoOfGuide=" + contactNoOfGuide + ", dateOfDeparture="
                + dateOfDeparture + ", mealRetrievalTime=" + mealRetrievalTime + "]";
    }

    @NotBlank(message = "Name Of Center is mandatory")
    private String nameOfCenter;

    @NotBlank(message = "Name Of Guide is mandatory")
    private String nameOfGuide;
    
    @NotBlank(message = "Head Count is mandatory")
    private int headCount;
    
    @NotBlank(message = "Mobile No Of Guide is mandatory")
    private String contactNoOfGuide;
    
    @NotBlank(message = "Date of Journey is mandatory")
    private Date dateOfDeparture;
    
    @NotBlank(message = "Journey meal retrival date and time is mandatory")
    private Date mealRetrievalTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getNameOfCenter() {
        return nameOfCenter;
    }

    public void setNameOfCenter(String nameOfCenter) {
        this.nameOfCenter = nameOfCenter;
    }

    public int getHeadCount() {
        return headCount;
    }

    public void setHeadCount(int headCount) {
        this.headCount = headCount;
    }

    public String getNameOfGuide() {
        return nameOfGuide;
    }

    public void setNameOfGuide(String nameOfGuide) {
        this.nameOfGuide = nameOfGuide;
    }

    public String getContactNoOfGuide() {
        return contactNoOfGuide;
    }

    public void setContactNoOfGuide(String contactNoOfGuide) {
        this.contactNoOfGuide = contactNoOfGuide;
    }

    public Date getDateOfDeparture() {
        return dateOfDeparture;
    }

    public void setDateOfDeparture(Date dateOfDeparture) {
        this.dateOfDeparture = dateOfDeparture;
    }

    public Date getMealRetrievalTime() {
        return mealRetrievalTime;
    }

    public void setMealRetrievalTime(Date mealRetrievalTime) {
        this.mealRetrievalTime = mealRetrievalTime;
    }
}

标签: spring-bootthymeleaf

解决方案


您需要添加您引用的对象th:object

 <form action="#" th:action="@{/addJourneyFoodOrder}" th:object="${journeyFoodOrder}" method="post">

我看到您提到它,但在 GET 映射中没有添加此模型属性。从您的 GET 映射中添加它,它应该可以正常工作。

乐:

您也可以使用此变体:

@GetMapping("/signup") public String showSignUpForm(JourneyFoodOrder journeyFoodOrder) { return "add-journeyFoodOrder"; }

推荐阅读