我正在构建一个分页表单,允许逐页遍历整个“Book”表,并允许一次提交更新整个记录页。
屏幕将具有包含文本框行和列的二维形式,如电子表格,其中每行对应于页面中的一个Book对象,每列对应Book对象的字段。
1.使用PagingAndSortingRepository检索页面记录
2.将书籍列表复制到由AutoPopulatingList支持的FormBean
我正在使用freemarker模板进行屏幕显示(因为Spring启动文档建议在开发Spring启动应用程序时避免使用JSP)
Q1)如何将AutopopulatingList绑定到freemarker的@Spring.bind并渲染一行@ spring.formInput文本框(每个Book字段一个文本框)(目前我使用普通html渲染它)和freemarker< #list>标签)
Q2)如何将提交的表单值读入myFormBean.AutoPopulatingList
//Form Bean backed by AutoPopulatingList
//Use AutoPopulatingList to allow flexible page sizes
public class MyBookListFormBean {
private AutoPopulatingList<Book> booksList;
//getter, setter, constructor
public void add(List<Book> books) {
booksList.addAll(books); //copy paged data into AutoPopulatingList
}
}
//show Form page method.
//This allows to navigate through the table
//and show a form screen per page of data which can be submitted to different URL.
//this method is run when "first/prev/next/last" links below the form are clicked
@RequestMapping(value="/books")
public String showPagedForm(Model model, Pageable page,
@ModelAttribute("booksForm") MyBookListFormBean formBean ) {
Page<Book> allBooks = booksRepository.findAll(pageable);
model.addAttribute("booksPage",allBooks);
formBean.addToList(allBooks.getContent()); //add current page data to Form Bean
return "/books/index";
}
//submit Form
@RequestMapping(value="/books/updateAPageOfRecords" method=RequestMethod.POST)
public String updateAPageOfRecords( Model model, Pageable page,
@ModelAttribute("booksForm") MyBookListFormBean formBean,
BindingResult result ) {
//tried to print the submitted data
//NOTHING got bound !!!
}