JavaWeb中Controller如何正确调用Service

Service层经常被调用,那么如何正确调用Service层并优化性能。
如下调用

1.在Controller中

XxService XxService = new XxService();

2.在Service中声明

Public static XxService me = new XxService(); 

在Controller中使用

XxService.me

3.....有没有更好的方式。在不使用依赖注入的情况下

阅读 8k
1 个回答

在controller中
private XxService XxService = new XxService();
直接new一个完事。
不明白为啥你不用注入?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进