mapper.xml
<mapper namespace="所对应的接口">
<sql id="sql1">sql语句起别名</sql>
<select id="和接口中方法对应" parameterType="int" resultType="user">
<include refid="sql1">或select语句
</select>
<select id="模糊查询" parameterType="String" parameterType="user">
select * from user where username like '%${value}%'
</select>
//插入并返回主键
<insert id="方法名" parameterType="user">
<selectKey keyProperty="id" order="AFTER" resultType="int">
select last_insert_id();
</selectKey>
insert into user(..) values(#{username}..)
</insert>
update/delete同理
</mapper>
其余标签:
<where>
<if test="username!=null and sex!=''">
and username like '%${username}%'
</if>
<if>..
</where>
<foreach collection="ids//list变量名" item="id" open="id in (" close=")" separator=",">
#{id}
</foreach>
注意:占位符#{}和连接符${}区别
占位符自带''
连接符不带''用于like
网友评论