【发布时间】:2019-04-07 02:58:26
【问题描述】:
我想在spring boot中实现自定义错误页面。在应用程序中,id 是主键,所以当没有给出 id 时,它会将请求传输到页面,但我希望应用程序在索引页面上显示带有错误消息的索引页面。实体类是
@Entity
public class Employee {
@Id
//@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
//@Id
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
private String name;
private String phone;
}
索引页是
<!DOCTYPE html>
<html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>index page</title>
</head>
<body>
<form action="#" th:action="@{/result}" th:object="${employee}" method="post">
<p>Id: <input type="text" th:field="*{id}" /></p>
<p>name: <input type="text" th:field="*{name}" /></p>
<p>phone: <input type="text" th:field="*{phone}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
我想在索引页面上显示错误,例如 id 字段更改颜色或在 id 列旁边有一条消息。
【问题讨论】:
-
似乎这与 Spring Boot 无关,而仅与前端表单验证有关。对吗?
标签: java spring spring-mvc spring-boot