部署后,模板可能不存在或可能无法由任何已配置的模板解析程序访问



出于某种原因,部署后,我在保存时开始给出 500 错误(也就是说,帖子满足了请求,但已经通过 get 重新加载同一页面会导致错误。第一次获取请求时,此页面将打开以显示填写表单(。尽管在本地计算机上一切正常。我寻求帮助!

我的绒球.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ru.asu</groupId>
<artifactId>pdn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pdn</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- JAXB -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.0.8</version>
</plugin>
</plugins>
</build>
</project>

我的控制器:

@GetMapping("/new_violation")
public String showNewViolationForm(Model model) {
Violation violation = new Violation();
model.addAttribute("violation", violation);
return "new_violation";
}
@PostMapping("/new_violation")
public String saveViolation(
@Valid @ModelAttribute Violation violation,
BindingResult bindingResult,
Model model
) {
if (bindingResult.hasErrors()) {
Map<String, String> errorsMap = getErrors(bindingResult);
model.mergeAttributes(errorsMap);
model.addAttribute("violation", violation);
} else {
violationService.save(violation);
}
return "/new_violation";
}

还有我的一些百里香叶:

<tr class="text-center">
<form action="#" method="post" th:action="@{/new_violation}" th:object="${violation}">
<div>
<th>
<label>
<input th:field="*{numProtocol}" type="text"/>
</label>
<span class="form-control is-invalid" th:errors="*{numProtocol}"
th:if="${#fields.hasErrors('numProtocol')}">
</span>
</th>
<th>
<label>
<input th:field="*{dateProtocol}" type="date"/>
</label>
<span class="form-control is-invalid" th:errors="*{dateProtocol}"
th:if="${#fields.hasErrors('dateProtocol')}">
</span>
</th>
<th>
<label>
<input th:field="*{violationAddress}" type="text"/>
</label>
<span class="form-control is-invalid" th:errors="*{violationAddress}"
th:if="${#fields.hasErrors('violationAddress')}">
</span>
</th>
<th>
<div>
<label>
<input th:field="*{child.fio}" type="text"/>
</label>
<span class="form-control is-invalid" th:errors="*{child.fio}"
th:if="${#fields.hasErrors('child.fio')}">
</span>
</div>
</th>
<th>
<label>
<input th:field="*{child.address}" type="text"/>
</label>
<span class="form-control is-invalid" th:errors="*{child.address}"
th:if="${#fields.hasErrors('child.address')}">
</span>
</th>
<th>
<button class="btn btn-primary bg-danger" type="submit">Сохранить</button>
</th>
</div>
</form>

看起来您的返回语句中有拼写错误。

而不是

return "/new_violation";

试试这个:

return "new_violation";

正如在您的获取映射中显示的那样。我假设您的帖子映射中也应该相同。

相关内容

最新更新