当我尝试以这种方式构建表单时出现错误:
public class Person {
private String name;
private int age;
public Person() {
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Controller
@RequestMapping("/")
public class TestController {
@GetMapping
public ModelAndView add() {
ModelAndView mav = new ModelAndView("index");
List<Person> persons = new ArrayList<>();
persons.add(new Person("Neon", 4));
mav.addObject("persons", persons);
return mav;
}
}
<form class="form-horizontal">
<div th:each="person,status : ${persons}" class="form-group" >
<label>Name</label><input th:field="${persons[__${status.index}__].name}" th:value="${person.name}" />
<label>Age</label><input th:field="${persons[__${status.index}__].age}" th:value="${person.age}" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
错误:
BindingResult和bean名称&#39;人员[0]&#39;可用作请求属性。
我想构建一个包含动态字段的表单
有人可以帮助我吗?
答案 0 :(得分:0)
问题是,您不能使用pipeline {
agent any
stages {
stage('build war') {
agent {
docker {
image 'gradle:latest'
reuseNode true
}
}
steps {
sh 'gradle war -b oven/build.gradle'
}
}
stage('test') {
steps {
script {
docker.image('mysql:latest').withRun('-e "MYSQL_ROOT_PASSWORD=password" -e "MYSQL_USER=root" -e "MYSQL_DATABASE=highlygroceries"') { c ->
docker.image('munhunger/highly-oven').withRun('-e "test=test"') { h ->
docker.image('mysql:latest').inside("--link ${c.id}:db") {
sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done'
}
docker.image('munhunger/highly-oven').inside("--link ${c.id}:db -e 'DB_URL=db:3306' -e 'DB_PASS=password' -e 'DB_USER=root'") {
sh 'sleep 5'
}
try {
docker.image('gradle:latest').inside("--link ${h.id}:backend -e 'OVEN_URL=http://backend:8080'") {
sh 'gradle test -b oven/build.gradle'
}
}
catch (exc) {
sh "docker logs ${h.id}"
throw exc
}
}
}
}
}
}
stage('build dockerimage') {
steps {
script {
dir('oven') {
def image = docker.build("munhunger/highly-oven")
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
image.push("${env.BUILD_NUMBER}")
image.push("latest")
}
}
}
}
}
}
}
作为要发布的对象。如果你构建另一个java对象(在我的例子中,使用List
的getter / setter)它应该可以工作
(示例)人员表格
List<Person> persons;
形式:
public class PersonForm {
private List<Person> persons = new ArrayList<>();
public List<Person> getPersons() {
return persons;
}
public void setPersons(List<Person> persons) {
this.persons = persons;
}
}