Binding between variable of html in string and a Model Class with Spring Boot

无人久伴 提交于 2019-12-20 05:40:38

问题


I want to create a binding between variables of html string and a Model Class for a spring boot app and then i will return a html page. Here what I need:

 @PostMapping(path = {"/hashmap"})
    public String GetHtmlPage(@RequestBody Owner owner) {

        String htmlPage=contractsRepository.getById(1);

        //i need a solution like "binding" method. 
        //but i don't know which library i can use and
        //how can i do this implementation
        String htmlPageAfterBinding=binding(htmlPage,owner);        

        return htmlPageAfterBinding;
    }

htmlPage will include a string like this:

...
  <p th:text="'Hello, ' + ${name} + '!'" />

  <tr th:each="book : ${books}">
        <td><span th:text="${book.title}"> Title </span></td>
        <td><span th:text="${book.author}"> Author </span></td>
  </tr>
...

and i will send a json request like this

{
   "name":"bookowner",
   "books":
  [
    {
           "title":"title1",
           "author":"author1"
    },
    {
        "title":"title2",
        "author":"author2"  
    }
   ]
}

my model classes like these

  class Owner{
    ...
    String name;
    Book[] books;
    ...
}

  class Book{
    ...
    String title;
    String author;
    ...
}

What kind of a solution do you suggest to me? Thanks for your helps.

来源:https://stackoverflow.com/questions/56742444/binding-between-variable-of-html-in-string-and-a-model-class-with-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!