【发布时间】:2021-04-12 12:53:57
【问题描述】:
这是我的TeacherController:
@Controller
@RequestMapping("/teacherController")
public class TeacherController {
private static final String TEACHER_MODEL = "teacher";
@Autowired
TeacherService teacherService;
@RequestMapping("check")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("teachers", teacherService.getAll());
modelAndView.setViewName("/teacherViews/teachersPage");
return modelAndView;
}
这里是我打印表格的页面:
<table class="table table-dark" border="1" width="100%" cellpadding="5">
<thead>
<tr>
<th>Teacher ID</th>
<th>Teacher Name</th>
<th>Teacher Position</th>
</tr>
</thead>
<tbody id="teacherBody">
<tr th:each="teacher : ${teachers}">
<td th:text="${teacher.teacherId}" />
<td th:text="${teacher.teacherName}" />
<td th:text="${teacher.position}" />
</tr>
</tbody>
我上面写的所有内容都需要使用 RestController 和 AJAX 重写。
据我了解,我希望该表数据自动加载加载页面,它可以与js一起使用。
所以,我的问题是我需要使用 AJAX 将我的 Controller 重写为 RestController,但我不明白该怎么做。
提前感谢您的帮助!!!
【问题讨论】:
标签: java ajax spring spring-restcontroller