<plugins> <plugin interceptor="com.rrtong.frame.dao.PaginationInterceptor"> <property name="dialect" value="oracle"/> </plugin> </plugins>
/*以下得到的是要执行的sql语句,并不是配置的sql语句*/ StatementHandler statementHandler = (StatementHandler)invocation.getTarget(); BoundSql boundSql = statementHandler.getBoundSql(); String originalSql = boundSql.getSql();
https://mybatis.googlecode.com/files/mybatis-spring-1.2.1.zip
mybatis 配置文件中的参数绑定区分大小写,必须与传递的参数名保持一致
1、设定entity的数据类型与数据库类型一致
2、在sql中定义参数的数据类型,比如
where userCode = #{userCode, jdbcType=VARCHAR}
<resultMap id="Archive" type="Archive"> <id column="ARCHIVESKEY" property="archiveKey" /> <result column="title" property="archiveTitle" /> </resultMap>
<p> <selectKey keyProperty="archiveKey" order="BEFORE" resultType="String"> SELECT SEQ_ARCHIVE.NEXTVAL FROM DUAL </selectKey></p>
<insert id="insertUser" useGeneratedKeys="true" keyProperty="userId" parameterType="com.mybatis.User"> insert into user(userName,password) values(#{userName},#{password}) </insert>
<resultMap id="Archive" type="Archive"> <id column="SPAARCHIVESKEY" property="archiveKey" /> <result column="title" property="archiveTitle" /> </resultMap> <select id="getArchive" parameterType="HashMap" resultMap="Archive"> select SPAARCHIVESKEY, TITLE from Archives where USERCODE = #{userCode, jdbcType=VARCHAR} And VALID= #{valid, jdbcType=VARCHAR} </select>
<update id="updateArchive" parameterType="Archive"> update Tbl_ARCHIVES set title = #{archiveTitle}, content = #{content}, feeValue = #{feeValue} security = #{security}, subjectType = #{subjectType}, gradeType = #{gradeType}, gather = #{gather}, archiveType = #{archiveType}, keyWordName = #{keyWordName} where archivesKey = #{archiveKey} </update>
<delete id="deleteArchive" parameterType="String"> delete from title where spaArchivesKey = #{archiveKey} </delete>
<sql id="addrColumn"> a.PUSH_ID, a.MEMBER_ID, a.CONTENT, a.PHOTO, a.PUSH_NAME, a.IS_AUTO, a.IS_FINE, a.IS_SOURCE, a.SOURCE_PUSH_ID, DATE_FORMAT(a.CREATE_TIME,'%Y-%m-%d %H:%i:%s') CREATE_TIME, DATE_FORMAT(a.DELETE_TIME,'%Y-%m-%d %H:%i:%s') DELETE_TIME </sql>引用复用的sql语句
<select id="getMyOrFineBlog" parameterType="MicroBlog" resultType="MicroBlog"> SELECT <include refid="addrColumn"/> FROM TBL_BLOG_PUSH a, TBL_USER_MEMBER b WHERE a.MEMBER_ID = b.MEMBER_ID <if test="isFine == 1"> AND a.IS_FINE = #{isFine} </if> </select>