<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.springboottest.dao.userDao">
<!--简单方式级联查询-->
<resultMap id="sampleSelectMap" type="com.example.springboottest.model.User">
<id property="id" column="id"></id>
<result property="userName" column="user_name"></result>
<result property="userPassword" column="user_password"></result>
<result property="userType" column="user_type"></result>
<association property="userProject" column="id" javaType="com.example.springboottest.model.UserProject">
<result property="stNumber" column="stNumber"></result>
<result property="project" column="project"></result>
</association>
<collection property="userCourseList" ofType="com.example.springboottest.model.UserCourse">
<result property="courseName" column="courseName"></result>
<result property="courseScore" column="courseScore"></result>
</collection>
</resultMap>
<select id="sampleSelect" resultMap="sampleSelectMap">
select a.id,a.user_name,a.user_password,a.user_type,b.stNumber,b.project,c.courseName,c.courseScore from userList a left join userProject b on a.id=b.userId left join userCourse c on a.id=c.userId
</select>
<!--级联查询-->
<resultMap id="getUserOneToOneAssociation" type="com.example.springboottest.model.User">
<id property="id" column="id"></id>
<association property="userProject" column="id" select="com.example.springboottest.dao.userProjectDao.findUserProjectByuserId"></association>
<collection property="userCourseList" column="id" select="com.example.springboottest.dao.userProjectDao.findUserCourseListByuserId"></collection>
</resultMap>
<select id="getUserOneToOne" resultMap="getUserOneToOneAssociation">
select * from userList
</select>
<!-- <sql id="sqlselect">-->
<!-- id,user_name,user_password,user_type-->
<!-- </sql>-->
<!-- <select id="getAllUser" resultType="com.example.springboottest.model.User">-->
<!-- select <include refid="sqlselect" /> from userList-->
<!-- </select>-->
<select id="getAllUserWhere" parameterType="string" resultType="com.example.springboottest.model.User">
select * from userList
<where>
<if test="userType !=null and userType !=''">
and user_type like '%${userType}%'
</if>
</where>
</select>
<!-- <select id="getAllUserWhere" parameterType="string" resultType="com.example.springboottest.model.User">-->
<!-- select * from userList where 1=1-->
<!-- <choose>-->
<!-- <when test="userType!='' and userType!=null">-->
<!-- and user_type like concat('%',#{userType},'%')-->
<!-- </when>-->
<!-- <when test="userName!='' and userName!=null">-->
<!-- and user_name like concat('%',#{userName},'%')-->
<!-- </when>-->
<!-- </choose>-->
<!-- </select>-->
<select id="getAllUser" resultType="com.example.springboottest.model.User">
select * from userList
</select>
<insert id="insertUser" parameterType="com.example.springboottest.model.User" keyProperty="id" useGeneratedKeys="true">
insert into userList (user_name,user_password,user_type) values (#{userName},#{userPassword},#{userType})
</insert>
<!-- <update id="updateUser" parameterType="com.example.springboottest.model.User">-->
<!-- update userList set user_name=#{userName},user_password=#{userPassword},user_type=#{userType} where id=#{id}-->
<!-- </update>-->
<update id="updateUser" parameterType="com.example.springboottest.model.User">
update userList
<set>
<if test="userName!='' and userName!=null">
user_name=#{userName},
</if>
<if test="userPassword!='' and userPassword!=null">
user_password=#{userPassword},
</if>
<if test="userType!='' and userType!=null">
user_type=#{userType},
</if>
</set>
where id=#{id}
</update>
<delete id="deleteUser" parameterType="long">
delete from userList where id in
<foreach item="id" index="index" collection="deleteList" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
mybatis 级联查询配置xml文件
最新推荐文章于 2024-06-12 11:08:31 发布