如何在胸腺中添加带有自己属性的对象列表?
很抱歉我的问题写了我的问题,但我无法真正用一个问题来解释我的问题。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<link href="/style.css" rel="stylesheet">
<title>Form Persona</title>
</head>
<body>
<h1>Aggiungi una persona</h1>
<form th:action="@{/persona}" method="POST" th:object="${persona}">
<div th:if="${#fields.hasGlobalErrors()}">
<p th:each="err : ${#fields.globalErrors()}" th:text="${err}">...</p>
</div>
<div>
<span>Nome:</span>
<span><input type="text" th:field="*{nome}"/></span>
<span th:if="${#fields.hasErrors('nome')}" th:errors="*{nome}"></span>
</div>
<div>
<span>Cognome:</span>
<span><input type="text" th:field="*{cognome}"/></span>
<span th:if="${#fields.hasErrors('cognome')}" th:errors="*{cognome}"></span>
</div>
<div>
<span>Età:</span>
<span><input type="text" th:field="*{eta}"/></span>
<span th:if="${#fields.hasErrors('eta')}" th:errors="*{eta}"></span>
</div>
<div>
<span><button type="submit">Conferma</button></span>
</div>
</form>
</body>
</html>
这是我在Springboot和Thymeleaf中使用的代码来添加一个新人,
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Entity
public class Persona {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank
private String nome;
@NotBlank
private String cognome;
@NotNull
@Min(0)
@Max(120)
private Integer eta;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public Integer getEta() {
return eta;
}
public void setEta(Integer eta) {
this.eta = eta;
}
public Long getId() {
return id;
}
@Override
public boolean equals(Object obj) {
Persona persona = (Persona)obj;
return this.nome.equals(persona.nome) &&
this.cognome.equals(persona.cognome) &&
this.eta.equals(persona.eta);
}
}
这是人类的班级。
现在,我想在人类类中添加一个新属性:list&lt; child&gt;儿童
。每个孩子都有一个名字和姓氏。如何将其添加到我的百里叶代码中? 谢谢您的帮助,如果您需要我发布更多的代码,请告诉我
I'm sorry for how i've written my question but I can't really explain my problem with a question.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<link href="/style.css" rel="stylesheet">
<title>Form Persona</title>
</head>
<body>
<h1>Aggiungi una persona</h1>
<form th:action="@{/persona}" method="POST" th:object="${persona}">
<div th:if="${#fields.hasGlobalErrors()}">
<p th:each="err : ${#fields.globalErrors()}" th:text="${err}">...</p>
</div>
<div>
<span>Nome:</span>
<span><input type="text" th:field="*{nome}"/></span>
<span th:if="${#fields.hasErrors('nome')}" th:errors="*{nome}"></span>
</div>
<div>
<span>Cognome:</span>
<span><input type="text" th:field="*{cognome}"/></span>
<span th:if="${#fields.hasErrors('cognome')}" th:errors="*{cognome}"></span>
</div>
<div>
<span>Età:</span>
<span><input type="text" th:field="*{eta}"/></span>
<span th:if="${#fields.hasErrors('eta')}" th:errors="*{eta}"></span>
</div>
<div>
<span><button type="submit">Conferma</button></span>
</div>
</form>
</body>
</html>
This is the code I'm using in springBoot with thymeleaf to add a new person,
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Entity
public class Persona {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank
private String nome;
@NotBlank
private String cognome;
@NotNull
@Min(0)
@Max(120)
private Integer eta;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public Integer getEta() {
return eta;
}
public void setEta(Integer eta) {
this.eta = eta;
}
public Long getId() {
return id;
}
@Override
public boolean equals(Object obj) {
Persona persona = (Persona)obj;
return this.nome.equals(persona.nome) &&
this.cognome.equals(persona.cognome) &&
this.eta.equals(persona.eta);
}
}
And this is the Person class.
Now I want to add a new attribute to the Person class: List<Child> children
. Every child has a name and a surname. How do I add it to my thymeleaf code?
Thank you for helping, if you need me to post more of my code, tell me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论