各位大牛 刚开始学Mybatis 我怎么看见有的人配置 resultMap里用实体类 有的人用java.util.HashMap 配置有啥诀窍啊

hadoop333 2015-01-12 11:32:21
各位大牛 刚开始学Mybatis 我怎么看见有的人配置 resultMap里用实体类 有的人用java.util.HashMap 配置有啥诀窍啊
在<select 标签里 有的人配置resultType="java.util.HashMap"
有的人配置 resultMap 我都搞糊涂了 谁能给我讲讲吗 有统一的标准吗
...全文
1494 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Laughing_Lz 2015-11-03
  • 打赏
  • 举报
回复
引用 2 楼 ch1240249252 的回复:
以下为个人理解 你说的两种方式一种是配置好实体类、那得建立在简单的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}
这个你selectList怎么写 返回List<HashMap<String,?>>, ?处该写什么呀?泛型吗?求指教
Joyce-Luo 2015-01-14
  • 打赏
  • 举报
回复
resultType只是指定当前的返回类型,当然就看你需要什么样的类型了,不过一般以对象居多,因为重用性就会增强
奄灬苟且偷生 2015-01-12
  • 打赏
  • 举报
回复
以下为个人理解 你说的两种方式一种是配置好实体类、那得建立在简单的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}
奄灬苟且偷生 2015-01-12
  • 打赏
  • 举报
回复
以下为个人理解 你说的两种方式一种是配置好实体类、那得建立在简单的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}
hadoop333 2015-01-12
  • 打赏
  • 举报
回复
引用 4 楼 u010880076 的回复:
ResultType可以是一个对象,或一个字段。 在返回一个list<user>时,你只要在ResultType中写下xxx.xxxx.user就可以。。。 ResultMap 一般多表联查时的返回结果,因为用一个对象无法装结果了,所以就用Map,这个map你可以在当前的xml中配制,也可以用util包下的map。
好的 我自己找点资料看看 thanks
程序袁_哈哈 2015-01-12
  • 打赏
  • 举报
回复
ResultType可以是一个对象,或一个字段。 在返回一个list<user>时,你只要在ResultType中写下xxx.xxxx.user就可以。。。 ResultMap 一般多表联查时的返回结果,因为用一个对象无法装结果了,所以就用Map,这个map你可以在当前的xml中配制,也可以用util包下的map。
YangSy_001 2015-01-12
  • 打赏
  • 举报
回复
ResultType 一般表示返回的是某个字段,代表这个字段的类型,ResultMap 一般返回的是实体 就是是你前面定义的<ResultMap>这个映射的ID

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧