Java SpringMVC:使用bean列表提交多行表单
我读了一些参考资料 试着重复一遍。首先,我用对象的属性列表创建包装器类。我把数据放在包装器对象中,把包装器对象放在我的get控制器模型中,你能看看我的代码吗: //============================================================Java SpringMVC:使用bean列表提交多行表单,java,thymeleaf,Java,Thymeleaf,我读了一些参考资料 试着重复一遍。首先,我用对象的属性列表创建包装器类。我把数据放在包装器对象中,把包装器对象放在我的get控制器模型中,你能看看我的代码吗: //============================================================ public class PupilsPerformanceWrapper { public List<JournalOfPupilsperformanceInLesson> listOfPerfor
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>
//========================================================================
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;
}
}
错误:bean类的无效属性“listOfPerformances[0]”
[PupilsPerformanceWrapper]:Bean属性“listOfPerformances[0]”为
不可读或具有无效的getter方法:的返回类型
getter是否与setter的参数类型匹配
有什么问题吗?您应该编写pupilPerf.mark1,而不是编写性能列表[index].mark1。 您无法在teymeleaf中获得此类迭代中的性能列表[index]。请参阅: