官网写的比较具体,可以查看以下的网站:

http://www.mybatis.org/mybatis-3/zh/configuration.html

另外,实际用到标准的CRUD的操作和查询列表,

<?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.iteye.tom.dao.AuthItemRecordDao"> <sql id="requestAllFields">
<![CDATA[
id,
record_time AS recordTime,
source_code AS sourceCode,
userid,
auth_item_id AS authItemId,
isvalid,
last_status_time AS lastStatusTime
]]>
</sql> <sql id="whereClause">
<where>
<if test="null!=id">AND id = #{id}</if>
<if test="null!=sourceCode and ''!=sourceCode">AND source_code = #{sourceCode}</if>
<if test="null!=userid and ''!=userid">AND userid = #{userid}</if>
<if test="null!=authItemId and ''!=authItemId">AND auth_item_id = #{authItemId}</if>
<if test="null!=isvalid and ''!=isvalid">AND isvalid = #{isvalid}</if>
<include refid="extendedWhereClause" />
</where>
</sql> <insert id="add" useGeneratedKeys="true" parameterType="com.iteye.tom.bean.AuthItemRecord" keyProperty="id">
INSERT INTO tab_auth_item_record
<trim prefix="(" suffix=")" prefixOverrides=",">
<if test="null!=recordTime">,record_time</if>
<if test="null!=sourceCode and ''!=sourceCode">,source_code</if>
<if test="null!=userid and ''!=userid">,userid</if>
<if test="null!=authItemId and ''!=authItemId">,auth_item_id</if>
<if test="null!=isvalid and ''!=isvalid">,isvalid</if>
<if test="null!=lastStatusTime">,last_status_time</if>
</trim>
VALUES
<trim prefix="(" suffix=")" prefixOverrides=",">
<if test="null!=recordTime">,#{recordTime}</if>
<if test="null!=sourceCode and ''!=sourceCode">,#{sourceCode}</if>
<if test="null!=userid and ''!=userid">,#{userid}</if>
<if test="null!=authItemId and ''!=authItemId">,#{authItemId}</if>
<if test="null!=isvalid and ''!=isvalid">,#{isvalid}</if>
<if test="null!=lastStatusTime">,#{lastStatusTime}</if>
</trim>
</insert> <update id="update" parameterType="com.iteye.tom.bean.AuthItemRecord">
UPDATE tab_auth_item_record
<trim prefix="SET" prefixOverrides=",">
<if test="null!=recordTime">,record_time = #{recordTime}</if>
<if test="null!=sourceCode and ''!=sourceCode">,source_code = #{sourceCode}</if>
<if test="null!=userid and ''!=userid">,userid = #{userid}</if>
<if test="null!=authItemId and ''!=authItemId">,auth_item_id = #{authItemId}</if>
<if test="null!=isvalid and ''!=isvalid">,isvalid = #{isvalid}</if>
<if test="null!=lastStatusTime">,last_status_time = #{lastStatusTime}</if>
<include refid="extendedUpdateSql" />
</trim>
WHERE id = #{id}
</update> <select id="query" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="com.iteye.tom.bean.AuthItemRecord">
SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record
<include refid="whereClause" />
<include refid="extendedOrderByClause" />
<if test="null!=requestOffset">
LIMIT #{requestOffset}, #{requestCount}
</if>
</select> <select id="get" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="com.iteye.tom.bean.AuthItemRecord">
SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record
<include refid="whereClause" />
LIMIT 1
</select> <select id="getById" parameterType="long" resultType="com.iteye.tom.bean.AuthItemRecord">
SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record WHERE id = #{id}
</select> <select id="count" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="int">
SELECT COUNT(1) FROM tab_auth_item_record <include refid="whereClause" />
</select> <delete id="deleteByUserid" parameterType="com.iteye.tom.bean.AuthItemRecord" >
DELETE FROM tab_auth_item_record WHERE userid = #{userid} </delete> <!-- 扩展的更新等语句(自定义)-->
<sql id="extendedUpdateSql">
<if test="null!=extendedParameter"> </if>
</sql> <!-- 扩展的条件过滤语句(自定义)-->
<sql id="extendedWhereClause">
<if test="null!=extendedParameter"> </if>
</sql> <!-- 扩展的排序等语句(自定义)-->
<sql id="extendedOrderByClause">
<if test="null!=extendedParameter"> </if>
</sql>
</mapper>

05-11 22:51