mybaits级联查询
mybatis怎么多表查询,在一对多的情况下
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.bbs.dao.PostDao"> <resultMap id="post" type="Post"> <id property="id" column="id" javaType="Integer"/> <result property="username" column="username" javaType="String"/> <result property="title" column="title" javaType="String"/> <result property="category" column="category" javaType="String"/> <result property="content" column="content" javaType="String"/> <result property="tag" column="tag" javaType="String"/> <result property="createTime" column="create_time" javaType="java.util.Date"/> <collection property="comment" column="id" javaType="Integer"> <id property="id" column="id" javaType="Integer"/> <result property="userId" column="user_id" javaType="Integer"/> <result property="username" column="username" javaType="String"/> <result property="content" column="content" javaType="String"/> <result property="createTime" column="create_time" javaType="java.util.Date"/> <result property="postId" column="post_id" javaType="Integer"/> </collection> </resultMap> <select id="selectById" parameterType="Integer" resultMap="post"> select p.*,c.username name,c.content con from post p left join comment c on p.id = c.post_id where p.id=#{id} </select> </mapper>
在查post表的时候一起把comment表的数据查出来,在post表中定义了一个comment的list集合对象。comment表中有一个post_id的字段对应post表中的id。弄了好久都没搞好,只能来求助老师了。
18
收起
正在回答 回答被采纳积分+1
2回答
相似问题
登录后可查看更多问答,登录/注册
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星