使用其他类控制器中的其他类存储库是正确的方法,或者使用RestTemplate类调用api是正确的方法

这是我发布任何想要获取特定用户的内容之前的发布控制器

@RequestMapping("/post")

public class PostController {

   @Autowired
   private PostRepository postRepository;

   @Autowired
   private UserRepository userRepository;
   ....
   ....
   .... 
}
帕万

最佳实践是,应该只在服务类中使用存储库。就像PostRepository in PostService不在控制器中一样。因此,我希望您可以编写服务并在控制器中使用该服务类,而不是直接在控制器中使用存储库。

为此,不需要REST调用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档