问题
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