但在mybatis中主从表需要为相同字段名设置别名。设置了别名就OK了。
一对多关联查询示例:一个角色对应多个权限
<resultMap id="rolePowerMap" type="com.lakala.creditloan.manager.model.Role"> <id column="roleId" property="roleId" jdbcType="INTEGER" /> <result column="ROLE_NAME" property="roleName" jdbcType="VARCHAR" /> <result column="rdescri" property="describe" jdbcType="VARCHAR" /> <collection property="powerlist" ofType="com.lakala.creditloan.manager.model.Power"> <id column="powerid" property="id" jdbcType="INTEGER" /> <result column="POWER_NAME" property="powerName" jdbcType="VARCHAR" /> <result column="ACTION_URL" property="actionUrl" jdbcType="VARCHAR" /> <result column="PID" property="pid" jdbcType="INTEGER" /> <result column="LV" property="lv" jdbcType="INTEGER" /> <result column="ACTION_TYPE" property="actionType" jdbcType="INTEGER" /> <result column="pdescri" property="descri" jdbcType="VARCHAR" /> </collection> </resultMap><select id="selectByRoleId" parameterType="java.lang.Integer" resultMap="rolePowerMap"> select r.ID roleId,r.ROLE_NAME,r.DESCRI rdescri, p.ID powerid,p.POWER_NAME,p.ACTION_URL,p.ACTION_URL,p.PID,p.LV,p.ACTION_TYPE,p.DESCRI pdescri from rcs_role r left join rcs_role_power rp on r.id=rp.ROLE_ID left join rcs_power p on p.ID=rp.POWER_ID where r.ID=#{roleId,jdbcType=INTEGER} </select>
新闻热点
疑难解答