Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将RowMapper类定义为Springbean可以吗?_Spring_Spring Jdbc - Fatal编程技术网

将RowMapper类定义为Springbean可以吗?

将RowMapper类定义为Springbean可以吗?,spring,spring-jdbc,Spring,Spring Jdbc,在许多关于SpringJDBC的教程/书籍中,RowMapper类通常在DAO中表示为private static final class,并且在每个查询中创建实例。 RowMapper是否必须以这种方式使用和实例化 如果我使用@Component注释和@Autowired将行映射器类定义为Springbean,可以吗 哪一个更好 RowMapper是否必须以这种方式使用和实例化 不,那只是一种常见的用法 如果我使用@Component注释和@Autowired将行映射器类定义为Springbe

在许多关于SpringJDBC的教程/书籍中,
RowMapper
类通常在DAO中表示为
private static final class
,并且在每个查询中创建实例。
RowMapper
是否必须以这种方式使用和实例化

如果我使用
@Component
注释和
@Autowired
行映射器
类定义为Springbean,可以吗

哪一个更好

RowMapper
是否必须以这种方式使用和实例化

不,那只是一种常见的用法

如果我使用
@Component
注释和
@Autowired
行映射器
类定义为Springbean,可以吗

当然,那会有用的。除非
RowMapper
需要访问其他Spring服务,否则没有什么意义

哪一个更好

如果看不到您的代码,也不了解您的应用程序,我们就无法真正告诉您这是不是一个好主意,只有您可以做出选择

我个人的偏好是将
行映射器
作为DAO类的一个非静态内部类,并直接从DAO中将其破坏。如果
RowMapper
需要访问其他springbean,那么将它们连接到DAO中,并从
RowMapper
内部类访问它们

RowMapper
是否必须以这种方式使用和实例化

不,那只是一种常见的用法

如果我使用
@Component
注释和
@Autowired
行映射器
类定义为Springbean,可以吗

当然,那会有用的。除非
RowMapper
需要访问其他Spring服务,否则没有什么意义

哪一个更好

如果看不到您的代码,也不了解您的应用程序,我们就无法真正告诉您这是不是一个好主意,只有您可以做出选择

我个人的偏好是将
行映射器
作为DAO类的一个非静态内部类,并直接从DAO中将其破坏。如果
RowMapper
需要访问其他springbean,那么将它们连接到DAO中,并从
RowMapper
内部类访问它们