map.xml范本:
<?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="dao">
</mapper>
insert
<insert id="insert" parameterType="model" useGeneratedKeys="true" keyProperty="id">
INSERT INTO table(
userId,
name,
age
) values (
#{userId},
#{name},
#{age}
)
</insert>
update
<update id="update" parameterType="model">
UPDATE
table
SET
name =#{registrationId},
age =#{lastLoginTime},
WHERE
userId =#{userId}
</update>
select:
<select id="select" parameterType="model" resultType="返回类型">
SELECT name,age FROM
table
WHERE
userId = #{userId}
</select>
sql标签:
jdbcType=DECIMAL,INTEGER,TIMESTAMP,VARCHAR
<sql id="Base_Column_List">
name,age
</sql>
对应
<include refid="Base_Column_List" />
大于: >
小于:<
<if test="">
</if>
<choose>
<when test="">
</when>
<when test="">
</when>
</choose>
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
IFNULL(#{age},0)
#当前时间减5天
DATE_SUB(now(),INTERVAL 5 DAY)
#当前时间加5天
DATE_ADD(now(),INTERVAL 5 DAY)
#时间转换字符串
DATE_FORMAT(now(),'%Y-%m-%d %H:%i')
返回周期两个时间之间的月数差
PERIOD_DIFF(DATE_FORMAT(endTime,'%Y%m'),DATE_FORMAT(startTime,'%Y%m'))