脚本宝典收集整理的这篇文章主要介绍了html5教程-Batis MyBatis关联查询示例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
MyBatis关联查询示例:
[html]
<resultMap type="UserView" id="userAndRoleViewResultMap">
<id column="user_id" property="userId"/>
<result column="loginname" property="loginname"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="user_rights" property="rights"/>
<result column="status" property="status"/>
<result column="last_login" property="lastLogin"/>
<association property="role" column="role_id" javaType="Role">
<id column="role_id" property="roleId"/>
<result column="role_name" property="roleName"/>
<result column="role_rights" property="rights"/>
</association>
</resultMap>
[sql]
<select id="listPageUser" parameterType="User" resultMap="userAndRoleResultMap">
select u.user_id,u.username,u.loginname,u.password,r.role_id,r.role_name ,u.last_login
from tb_user u
left join tb_role r on u.role_id=r.role_id
where u.status=0
<if test="loginname!=null and loginname!=''">
and u.loginname like "%"#{loginname}"%"
</if>
<if test="roleId!=null and roleId!=0">
and u.role_id=#{roleId}
</if>
<if test="lastLoginStart!=null">
and u.last_login>=#{lastLoginStart}
</if>
<if test="lastLoginEnd!=null">
and u.last_login<=#{lastLoginEnd}
</if>
</select>
MyBatis关联查询示例:
[html]
<resultMap type="UserView" id="userAndRoleViewResultMap">
<id column="user_id" property="userId"/>
<result column="loginname" property="loginname"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="user_rights" property="rights"/>
<result column="status" property="status"/>
<result column="last_login" property="lastLogin"/>
<association property="role" column="role_id" javaType="Role">
<id column="role_id" property="roleId"/>
<result column="role_name" property="roleName"/>
<result column="role_rights" property="rights"/>
</association>
</resultMap>
[sql]
<select id="listPageUser" parameterType="User" resultMap="userAndRoleResultMap">
select u.user_id,u.username,u.loginname,u.password,r.role_id,r.role_name ,u.last_login
from tb_user u
left join tb_role r on u.role_id=r.role_id
where u.status=0
<if test="loginname!=null and loginname!=''">
and u.loginname like "%"#{loginname}"%"
</if>
<if test="roleId!=null and roleId!=0">
and u.role_id=#{roleId}
</if>
<if test="lastLoginStart!=null">
and u.last_login>=#{lastLoginStart}
</if>
<if test="lastLoginEnd!=null">
and u.last_login<=#{lastLoginEnd}
</if>
</select>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! html5教程,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的html5教程-Batis MyBatis关联查询示例全部内容,希望文章能够帮你解决html5教程-Batis MyBatis关联查询示例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。