其他分享
首页 > 其他分享> > 阿里禁用select *,spring推荐使用构造器注入---why?

阿里禁用select *,spring推荐使用构造器注入---why?

作者:互联网

select *

阿里开发手册中规定:【强制】在表查询中,一律不要使用 * 作为查询的字段列表,需要哪些字段必须明确写明。

原因

spring构造注入

在开发中@Autowired或者@Resource使用起来及其方便、简单。
但是每次使用是都有个小问题
在这里插入图片描述
直译为:不建议现场注入

原因

官方文档给的解释:
The Spring team generally advocates constructor injection as it enables one to implement application components as immutable objects and to ensure that required dependencies are not null. Furthermore constructor-injected components are always returned to client (calling) code in a fully initialized state.
翻译:
Spring团队通常提倡构造函数注入,因为它使人们能够将应用程序组件实现为不可变对象,并确保所需的依赖项不为null。此外,构造函数注入的组件总是以完全初始化的状态返回给客户机(调用)代码。
原因很明显了

结束语

对个人碰见的疑惑进行归纳解答。-----做记录

标签:初始化,构造方法,spring,---,实例,Spring,构造函数,why,注入
来源: https://blog.csdn.net/dm1215104744/article/details/118791408