编写Web访问层Controller文件

4次阅读

共计 790 个字符,预计需要花费 2 分钟才能阅读完成。

编写 Web 访问层 Controller 文件

java

@RestController

@RequestMapping(“api”) // 窄化请求路径

public class ApiCommentController {

@Autowired

private ApiCommentService commentService;

@RequestMapping(value = “/findCommentById”)

public Comment findCommentById(Integer id){

Comment comment = commentService.findCommentById(id);

return comment;

}

@RequestMapping(value = “/updateComment”)

public void updateComment(Comment comment){

Comment comment2 = commentService.findCommentById(comment.getId());

comment.setAuthor(comment.getAuthor());

commentService.updateComment(comment);

}

@RequestMapping(value = “/deleteComment”)

public void deleteComment(int id){

commentService.deleteComment(id);

}

}

* 基于 API 的 Redis 缓存实现的相关配置。基于 API 的 Redis 缓存实现不需要 @EnableCaching 注解开启基于注解的缓存支持,所以这里可以选择将添加在项目启动类上的 @EnableCaching 进行删除或者注释

这些内容,是从拉勾教育的《Java 工程师高薪训练营》里学到的,课程内容非常全面,还有拉勾的内推大厂服务,推荐你也看看。

正文完
 0