Для обслуживания html-контента, если он статический, вы можете использовать конечную точку контроллера, например:
@GetMapping(value = "/")
public Employee readData () {
return "employee";
}
, и springboot вернет статическую html-страницу с именем "employee". Но в вашем случае вам нужно вернуть карту modelandview, чтобы динамические данные отображались в формате html:
@GetMapping(value = "/")
public Employee readData (Model model) {
Employee employee = new Employee();
employee.setName("GG");
employee.setAddress("address");
employee.setPostCode("postal code");
model.addAttribute("employee",employee)
return "employee";
}
Также удалите аннотацию @RestController
из вашего класса и добавьте @Controller
.
В противном случае, , если ваш сценарий использования требует, чтобы вы возвращали html-контент из конечной точки REST , тогда используйте:
@RestController
@RequestMapping(value = "/v1/files")
public class DataReader {
@GetMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
public Employee readData () {
// employees fetched from the data base
String html = "<HTML></head> Employee data converted to html string";
return html;
}
}
или используйте return ResponseEntity.ok('<HTML><body>The employee data included as html.</body></HTML>')