Java 我的Thymeleaf/HTML没有';I don’我不喜欢th:前缀,当页面位于表单中时,将不会呈现该页面

Java 我的Thymeleaf/HTML没有';I don’我不喜欢th:前缀,当页面位于表单中时,将不会呈现该页面,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我有一个表单(使用Java、Springboot和Thymeleaf),它不喜欢在输入区域之前添加th:前缀。如果th:在html中,则不会呈现整个页面。如果我把它取出来,页面就会呈现出来,但是我没有得到实际的客户端输入,我认为这是因为它不是一个合适的形式。有没有办法解决这个问题?我是不是错过了一个依赖点或者幕后的什么 POM文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apach

我有一个表单(使用Java、Springboot和Thymeleaf),它不喜欢在输入区域之前添加th:前缀。如果th:在html中,则不会呈现整个页面。如果我把它取出来,页面就会呈现出来,但是我没有得到实际的客户端输入,我认为这是因为它不是一个合适的形式。有没有办法解决这个问题?我是不是错过了一个依赖点或者幕后的什么

POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.Oli</groupId>
  <artifactId>ResourceWebsite</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>OliAffiliatePortal</name>
  <description>Demo project for Spring Boot</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath/>
    <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-activemq</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>nz.net.ultraq.thymeleaf</groupId>
      <artifactId>thymeleaf-layout-dialect</artifactId>
      <version>1.3.3</version>
    </dependency>
    <dependency>
      <groupId>org.thymeleaf.extras</groupId>
      <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>com.microsoft.sqlserver</groupId>
      <artifactId>mssql-jdbc</artifactId>
      <version>6.1.0.jre8</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>3.2.8.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.thymeleaf.extras</groupId>
      <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    </dependency>

    <dependency>
      <groupId>org.thymeleaf.extras</groupId>
      <artifactId>thymeleaf-extras-java8time</artifactId>
      <version>2.1.0.RELEASE</version>
    </dependency>
    <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>-->
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>


</project>
我的HTML/表单

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml" xmlns:modelAttributeth="http://www.w3.org/1999/xhtml" xmlns:form="http://www.w3.org/1999/xhtml">

<head>
  <meta charset="UTF-8" />
  <title>DirectBind</title>
  <link th:replace="fragments/header :: head" />
</head>

<body>

  <div th:if="${param.sentMessageFail}">
    <div class="ui warning message">
      <i class="close icon"></i>
      <div class="header">
        Oops, your message failed to send!
      </div>
      Please try again, or send us an email at <a href="mailto:InternetBusinessDivision@Heffins.com">InternetBusinessDivision@Heffins.com</a>
    </div>
  </div>
  <div th:if="${param.sentMessage}">
    <div class="ui positive message">
      <i class="close icon"></i>
      <div class="header">
        Thank you for your message!
      </div>
      <p>We'll get back to you as soon as we can.</p>
    </div>
  </div>

  <form:form enctype="multipart/form-data" id="form" class="ui form" th:object="${directBind}" method="POST" th:action="@{/send}">
    <div class="field">
      <label>Contact Name</label>
      <input type="text" th:field="*{contactName}" />
    </div>
    <div class="field">
      <label>Address</label>
      <textarea th:field="*{formAddress}"></textarea>
    </div>
    <div class="two fields">
      <div class="field">
        <label>Phone Number</label>
        <input type="text" th:field="*{phoneNumber}" />
      </div>

    </div>
    <div class="ui fluid buttons">
      <a class="ui button" onclick="clearForm()">Clear</a>
      <div class="or"></div>
      <button class="ui blue button">Send</button>
    </div>
  </form:form>

</body>

</html>

直接绑定
哎呀,你的消息发送失败!
请重试,或发送电子邮件至
谢谢你的留言!
我们会尽快给你回复

联系人姓名 住址 电话号码 清楚的 邮寄
表单的我的控制器:

package com.Oli.ResourceWebsite.controllers; 

import com.Oli.ResourceWebsite.models.OliDb.Document; 
import com.Oli.ResourceWebsite.models.ResourceWebsite.DirectBind; 
import com.Oli.ResourceWebsite.models.ResourceWebsite.Mail; 
import com.Oli.ResourceWebsite.services.EmailService;
import com.Oli.ResourceWebsite.services.StorageService; 
import com.sun.media.jfxmedia.logging.Logger; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.mail.MailException;
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping; 
import org.springframework.web.multipart.MultipartFile; 
import java.util.*; 

@Controller 
public class DirectBindController { 
  @Autowired private EmailService emailService; 

  @GetMapping("/directBind") 
  public String getDirectBind(Model model){ 
    DirectBind directBind = new DirectBind(); 
    return "directBind"; 
  } 

  @PostMapping(value="/send") 
  public String send(Model model, @ModelAttribute(value="directBind") DirectBind directBind) { 
    Mail mail = new Mail(); 
    mail.setFrom("no-reply@hgitservices.com"); 
    mail.setTo(new String[]{"stacief@hgitservices.com"}); 
    mail.setSubject("IME Self Support - User Message"); 

    Map<String, Object> mailModel = new HashMap<String, Object>(); 
    mail.setModel(mailModel); 
    try { 
      emailService.sendSimpleMessage(mail, directBind); 
    } catch (Exception e) { 
      e.printStackTrace(); 
      return ("redirect:/?sentMessageFail"); 
    } return ("redirect:/?sentMessage"); 
  } 

  @RequestMapping(value="/email")
  public String email() { 
    return "emailMessage"; 
  } 
package com.Oli.ResourceWebsite.controllers;
导入com.Oli.ResourceWebsite.models.OliDb.Document;
导入com.Oli.ResourceWebsite.models.ResourceWebsite.DirectBind;
导入com.Oli.ResourceWebsite.models.ResourceWebsite.Mail;
导入com.Oli.ResourceWebsite.services.EmailService;
导入com.Oli.ResourceWebsite.services.StorageService;
导入com.sun.media.jfxmedia.logging.Logger;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.mail.MailException;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.PostMapping;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.multipart.MultipartFile;
导入java.util.*;
@控制器
公共类DirectBindController{
@自动连线私人电子邮件服务;
@GetMapping(“/directBind”)
公共字符串getDirectBind(模型){
DirectBind DirectBind=新的DirectBind();
返回“directBind”;
} 
@PostMapping(value=“/send”)
公共字符串发送(模型模型,@modeldattribute(value=“directBind”)directBind directBind){
邮件=新邮件();
mail.setFrom(“否-reply@hgitservices.com"); 
mail.setTo(新字符串[]{”stacief@hgitservices.com"}); 
mail.setSubject(“IME自我支持-用户消息”);
Map mailModel=newhashmap();
setModel(mailModel);
试试{
emailService.sendSimpleMessage(邮件,directBind);
}捕获(例外e){
e、 printStackTrace();
返回(“重定向:/?sentMessageFail”);
}返回(“重定向:/?发送消息”);
} 
@请求映射(value=“/email”)
公共字符串电子邮件(){
返回“emailMessage”;
} 

您忘记在html页面中插入以下内容:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">


没有此声明,您的页面无法处理thymelaf。

请查看您的帖子;代码需要格式化,我认为您的控制器粘贴出现问题。如果您使用Spring引导,请删除显式thymelaf配置。同时从依赖项中删除
Spring上下文支持
(因为这是从较旧的Spring版本开始的,您已经从Spring Boot获得了正确的版本)。从
thymeleaf-extras-java8time
中删除该版本,并且
thymeleaf布局方言
Spring Boot将管理这些。最后,您的
xmlns:th
应该是
xmlns:th=”http://www.thymeleaf.org"
不是您现在拥有的。或者您可以使用
data th xxx
方法。更改xmlns语句没有帮助。我只是在执行处理器“org.thymeleaf.spring4.processor.attr.springInputGeneralFieldDattrProcessor”时不断收到相同的错误:error,引用显示th:字段的第一行。另外,如果我删除使用前缀,表单将加载,但在提交时不会从表单中获取客户端的输入。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">