这是我的 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将我的控制器重写为restcontroller,但我不知道怎么做。
提前感谢您的帮助!!!
1条答案
按热度按时间yhxst69z1#
@controller和@rest controller的区别
@控制器
@controller注解已经成为框架的一部分很长时间了。@controller注解指定被注解的类是控制器。它是@controller的专门化,通过类路径扫描自动检测。它通常用于与基于@requestmapping注解的带注解处理程序方法的合并。
例如,
请求处理方法用@responsebody注解。此注解支持将返回对象自动序列化到httpresponse中。
@REST控制器
@restcontroller注解在spring4.0中引入,以简化restfulweb服务的产生。它是一个方便的注解,结合了@controller和@responsebody
例如,
控制器使用@restcontroller注解进行注解,因此不需要@responsebody。控制器类的每个请求处理方法都自动将返回对象序列化为httpresponse。链接
转换后
REST控制器
html格式
javascript(未测试)