【问题标题】:Spring Roo Detail ObjectSpring Roo 细节对象
【发布时间】:2018-12-14 10:16:17
【问题描述】:

我正在使用 Spring roo v2.0。我创建了一个包含两个实体的简单应用程序:Library 和 Book。一个图书馆可以有更多的书,所以我创建了一个一对多的关系。 我使用以下命令创建项目:

project setup --topLevelPackage com.library 
jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY 
entity jpa --class ~.Library 
field string --fieldName identifier  --notNull
entity jpa --class ~.Book  
field string --fieldName identifier  --notNull
focus --class ~.Library
field set --fieldName book --type ~.Book --mappedBy library --notNull false --cardinality ONE_TO_MANY
repository jpa --all --package ~.repository
service --all --apiPackage ~.service.api --implPackage ~.service.impl 
web mvc setup
web mvc view setup --type THYMELEAF
web mvc controller --all --responseType JSON
web mvc controller --all --responseType THYMELEAF
web mvc detail --all --responseType THYMELEAF

我的问题.. 当我编辑/显示图书馆详细信息时,我想在选择一个之后在列表图书馆页面中显示其书籍。

然后...在这种形式中,我想要一个添加按钮,为该图书馆创建一本书,而不是通用书。

我该怎么做?谢谢指教

【问题讨论】:

    标签: thymeleaf spring-roo


    【解决方案1】:

    您应该手动自定义与Library 实体相关的show.html 视图,以包含包含该信息的表格。

    为此,您可以在为show 页面提供服务的方法的model 中包含使用findBooksByLibrary 方法的完整图书列表。像这样的:

    @Override
    @GetMapping(name = "show")
    public ResponseEntity<Library> show(@ModelAttribute Library library, Model model) {
       model.addAttribute("books", getBookService().findByLibrary(library));
       return new ModelAndView("libraries/show");
    }
    

    之后,编辑show.html 页面,包括一个显示以前相关书籍的table 元素:

    <table data-th-each="item : ${books}">
     <tr>
       <td data-th-text="${item.identifier}"></td>
     </tr>
    </table>
    

    注意:请记住,您可以使用 Datatables JQuery 插件为上表提供额外的功能。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多