真正的问题是,为什么允许我通过以下两种方式编写此代码:
@Controller
public class PostController {
@Autowired
private PostService postService;
@Autowired
private CommentService commentService;
....
}
和
@Controller
public class PostController {
private PostService postService;
private CommentService commentService;
@Autowired
public PostController(PostService postService,CommentService commentService){
this.postService = postService;
this.commentService = commentService;
}
....
}
这些摘要是否相同?推荐哪一个?
最佳答案
原文链接:https://www.f2er.com/spring/531782.html