Spring Boot and Swagger text/html response mapping
There is no way (no already existing way) to map POJO fields to html with annotations.
Instread one can bind POJOs (model) to html using other means Spring proposes out of the box: Thymleaf temlates, Freemarker templates and JSP pages.
Here is an example of one of the possible solutions:
- Create HTML page using html Thymleaf template. For example a
table.html
view:
<body>
<table>
<tr>
<th>Key</th>
<th>Name</th>
</tr>
<tr th:each="mapEnty: ${mapNames}">
<td th:text="${mapEnty.key}" />
<td th:text="${mapEnty.value}" />
</tr>
</table>
</body>
- Create a @RequestMapping for 'text/html' Content type in a Spring
@Controller
, fill in the Model and return the 'table' view. For example:
@GetMapping(value = "/api/javainuse", produces = MediaType.TEXT_HTML_VALUE)
public String table(Model model) {
Map<String, String> mapNames = new HashMap<String, String>();
...
model.addAttribute("mapNames", mapNames);
return "table";
}