gpt4 book ai didi

java - Spring MVC : Multiple Row Form Submit using List of Beans

转载 作者:行者123 更新时间:2023-12-01 23:34:11 24 4
gpt4 key购买 nike

我读过一些资源https://www.viralpatel.net/spring-mvc-multi-row-submit-java-list/并尝试重复这一点。首先,我创建带有属性的包装类 - 对象列表。我将我的数据放入包装对象中,将包装对象放入我的获取 Controller 的模型中,你能看一下我的代码吗:

//================================================ ===============

public class PupilsPerformanceWrapper {

public List<JournalOfPupilsperformanceInLesson> listOfPerformances;

//constructor and methods get and set and method addPupilPerformance

}

//================================================ =============

public class PupilsPerformanceController {
@RequestMapping(value = "/pupilsperformance_in_lesson/lessonId={id}", method = RequestMethod.GET)
public ModelAndView showForm (@PathVariable("id") UUID LessonJournalId, Model model) {


final JournalOfLessonRepository LessonJournalRepo = appContext.getBean(JournalOfLessonRepository.class);
final JournalOfLesson journalOfLesson = LessonJournalRepo.findById(LessonJournalId).get();


final var it = Repo.findByLesson(journalOfLesson);

PupilsPerformanceWrapper pupilPerformanceWrapper = new PupilsPerformanceWrapper();
it.forEach(e -> pupilPerformanceWrapper.addPupilPerformance(e));

model.addAttribute("pupilPerformanceWrapper", pupilPerformanceWrapper);
final ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("JournalOfPupilsperformanceInLesson/PerformanceList");
return modelAndView;
}
}

//================================================ ===========================HTML 文件

<form th:object = "${pupilPerformanceWrapper}">
<div th:each="pupilPerf, stat: *{listOfPerformances}" >
<input type="hidden" th:field="*{listOfPerformances[__${stat.index}__].mark1}" value="${pupilPerf.mark1}"/>
</div>
</form>

//================================================ ===========================

ERROR: Invalid property 'listOfPerformances[0]' of bean class [PupilsPerformanceWrapper]: Bean property 'listOfPerformances[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

怎么了?

最佳答案

不应编写 listOfPerformances[index].mark1 ,而应编写 doctorPerf.mark1 。您无法在 teymeleaf 的此类迭代中获得 listOfPerformances[index] 。请引用:https://www.baeldung.com/thymeleaf-iteration

关于java - Spring MVC : Multiple Row Form Submit using List of Beans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58281175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com