以下为个人理解
你说的两种方式一种是配置好实体类、那得建立在简单的SQL语句 如select * from table
hashmap就不用考虑返回的数据对应的类了 比如下方的SQL语句我就用hashmap、其实是我比较懒、勿喷
select
B.id as blog_id,
B.title as blog_title,
B.author_id as blog_author_id,
A.id as author_id,
A.username as author_username,
A.password as author_password,
A.email as author_email,
A.bio as author_bio,
A.favourite_section as author_favourite_section,
P.id as post_id,
P.blog_id as post_blog_id,
P.author_id as post_author_id,
P.created_on as post_created_on,
P.section as post_section,
P.subject as post_subject,
P.draft as draft,
P.body as post_body,
C.id as comment_id,
C.post_id as comment_post_id,
C.name as comment_name,
C.comment as comment_text,
T.id as tag_id,
T.name as tag_name
from Blog B
left outer join Author A on B.author_id = A.id
left outer join Post P on B.id = P.blog_id
left outer join Comment C on P.id = C.post_id
left outer join Post_Tag PT on PT.post_id = P.id
left outer join Tag T on PT.tag_id = T.id
where B.id = #{id}
你说的两种方式一种是配置好实体类、那得建立在简单的SQL语句 如select * from table
hashmap就不用考虑返回的数据对应的类了 比如下方的SQL语句我就用hashmap、其实是我比较懒、勿喷
select
B.id as blog_id,
B.title as blog_title,
B.author_id as blog_author_id,
A.id as author_id,
A.username as author_username,
A.password as author_password,
A.email as author_email,
A.bio as author_bio,
A.favourite_section as author_favourite_section,
P.id as post_id,
P.blog_id as post_blog_id,
P.author_id as post_author_id,
P.created_on as post_created_on,
P.section as post_section,
P.subject as post_subject,
P.draft as draft,
P.body as post_body,
C.id as comment_id,
C.post_id as comment_post_id,
C.name as comment_name,
C.comment as comment_text,
T.id as tag_id,
T.name as tag_name
from Blog B
left outer join Author A on B.author_id = A.id
left outer join Post P on B.id = P.blog_id
left outer join Comment C on P.id = C.post_id
left outer join Post_Tag PT on PT.post_id = P.id
left outer join Tag T on PT.tag_id = T.id
where B.id = #{id}
解决方案 »
- Caused by: org.hibernate.InvalidMappingException: Could not parse mapping docume
- javamail不能发送给gmail和hotmail................................................
- struts怎么把文件上传到相对路径
- tomcat重发布出错
- 无法登陆服务器
- 开发EJB项目是使用eclipse好还是NetBeans好?
- 请问安装一下Oracle需要多大的硬盘空间!
- hibernate中如果用数据库提供的级联删除更新会如何
- WebLogic 怎么运行 (或代理运行) PHP 程序?
- 如何在bmp管理的ejb中查找数据库?
- spring + jspsmartupload 一直有空指针异常怎么处理?
- java开发的BS项目里异常一般怎么处理啊 我们可以再catch里往log4j里写入日志 但是出了异常 展示的页面一般怎么办呢
你说的两种方式一种是配置好实体类、那得建立在简单的SQL语句 如select * from table
hashmap就不用考虑返回的数据对应的类了 比如下方的SQL语句我就用hashmap、其实是我比较懒、勿喷
select
B.id as blog_id,
B.title as blog_title,
B.author_id as blog_author_id,
A.id as author_id,
A.username as author_username,
A.password as author_password,
A.email as author_email,
A.bio as author_bio,
A.favourite_section as author_favourite_section,
P.id as post_id,
P.blog_id as post_blog_id,
P.author_id as post_author_id,
P.created_on as post_created_on,
P.section as post_section,
P.subject as post_subject,
P.draft as draft,
P.body as post_body,
C.id as comment_id,
C.post_id as comment_post_id,
C.name as comment_name,
C.comment as comment_text,
T.id as tag_id,
T.name as tag_name
from Blog B
left outer join Author A on B.author_id = A.id
left outer join Post P on B.id = P.blog_id
left outer join Comment C on P.id = C.post_id
left outer join Post_Tag PT on PT.post_id = P.id
left outer join Tag T on PT.tag_id = T.id
where B.id = #{id}
在返回一个list<user>时,你只要在ResultType中写下xxx.xxxx.user就可以
ResultMap 一般多表联查时的返回结果,因为用一个对象无法装结果了,所以就用Map,这个map你可以在当前的xml中配制,也可以用util包下的map。