分享

MyBatis多表关联查询 – 蓝海魔方

 ajax111 2015-05-18
  1. <resultMap id="BaseResultMap" type="com.lssrc.cms.dto.JobDto" >
  2. <id column="j_id" property="jId" jdbcType="VARCHAR" />
  3. <result column="j_title" property="jTitle" jdbcType="VARCHAR" />
  4. <result column="j_belong" property="jBelong" jdbcType="VARCHAR" />
  5. <result column="j_type" property="jType" jdbcType="VARCHAR" />
  6. <result column="j_content" property="jContent" jdbcType="LONGVARCHAR" />
  7. <association property="jobBelong" javaType="com.lssrc.cms.entity.JobBelong">
  8. <id column="jb_id" property="jbId" jdbcType="VARCHAR" />
  9. <result column="jb_name" property="jbName" jdbcType="VARCHAR" />
  10. </association>
  11. <association property="jobType" javaType="com.lssrc.cms.entity.JobType">
  12. <id column="jt_id" property="jtId" jdbcType="VARCHAR" />
  13. <result column="jt_name" property="jtName" jdbcType="VARCHAR" />
  14. </association>
  15. </resultMap>

在SQL中这样写就可以:

  1. <select id="selectByPage" resultMap="BaseResultMap">
  2. select
  3. *
  4. from shsj_job, shsj_job_belong, shsj_job_type
  5. where
  6. shsj_job.j_type=shsj_job_type.jt_id and
  7. shsj_job.j_belong=shsj_job_belong.jb_id
  8. order by j_id desc
  9. limit #{start},#{pageSize}
  10. </select>

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约