SpringFramework JdbcTemplate RowMapper
我想知道 JdbcTemplate 和 RowMapper 是否支持复杂的对象检索。 我在谷歌上找不到任何关于此事的信息(标准错误?)。 :(
示例:
public class Person() {
private Long id;
private String name;
private PersonDetail personDetail;
}
public class PersonDetail() {
...
}
表格看起来与对象相同。
我想要做的是以下内容: 创建一个 PersonRowMapper,在映射器中 PersonalDetail 也将被映射为一个对象(如果您定义了关系,hibernate 将为您做什么)。
非常感谢, 菲罗内
I am wondering if JdbcTemplate and RowMapper supports complex object retrieval.
I couldn't find anything with google on this matter (Wrong criteria?). :(
Example:
public class Person() {
private Long id;
private String name;
private PersonDetail personDetail;
}
public class PersonDetail() {
...
}
Tables will look the same as the objects.
What I would like to do is the following:
Create a PersonRowMapper, within the mapper PersonalDetail will be also mapped as an object (what hibernate will do for you if you have a relationship defined).
Many thanks,
Firone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然...只是,您必须确保您的查询处理 select 子句中的联接和所有必需的值,然后像设置 Person 一样设置 personDetail 的字段(在实例化新的 PersonDetail 之后)。
如果您想要一个 PersonDetails 列表并扩充它们(即一对多),JdbcTemplate 可以使机制和语法更简单,但您必须相当手动地处理关系及其查询。或者使用休眠。
Sure...only, you'll have to make sure your query handles the joins and all the required values in the select clause, then set personDetail's fields just as you would Person's (after instantianting a new PersonDetail).
If you wanted to have a list of PersonDetails and inflate them (i.e., one to many), JdbcTemplate can make the machanics and syntax simpler but you will have to handle the relationship and its queries fairly manually. Or use Hibernate.