The experience of using mybatis query

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
[size=small][size=xx-large][size=medium][size=xx-small]Today to share with you use mybatis query, hope my share to help people in need


Mybatis queries are mainly three ways to achieve:

A: <select id= "selectResouceInfoByNotNullAttributes" resultMap= "ExpandResultMap" parameterType= "bean class name">    select * from table_name where 1=1      <if test="resourceId != null">        and resource_id = #{resourceId,jdbcType=INTEGER}      </if>      <if test="appid != null">       and  appid = #{appid,jdbcType=TINYINT}      </if>      <if test="resourceUrl != null">       and  resource_url = #{resourceUrl,jdbcType=VARCHAR}      </if>      <if test="resourceDesc != null">       and  resource_desc = #{resourceDesc,jdbcType=VARCHAR}      </if>  </select>

Key points this way behind where 1=1, and this can avoid is after the first if conditions need to add and selection dilemma.
Mode two: <select id= "selectResouceInfoByNotNullAttributes" resultMap= "ExpandResultMap" parameterType= "bean class name">    Select * from table name    <where>      <if test="resourceId != null">        and resource_id = #{resourceId,jdbcType=INTEGER}      </if>      <if test="appid != null">       and  appid = #{appid,jdbcType=TINYINT}      </if>      <if test="resourceUrl != null">       and  resource_url = #{resourceUrl,jdbcType=VARCHAR}      </if>      <if test="resourceDesc != null">       and  resource_desc = #{resourceDesc,jdbcType=VARCHAR}      </if>    </where>  </select>

In this way than the first kind of an where tag, and does not require a 1=1 field is displayed in the where later added.
Mode three: <select id= "selectResouceInfoByNotNullAttributes" resultMap= "ExpandResultMap" parameterType= "bean class name">    Select * from table name    <trim prefix = "where" prefixOverrides="and|or">      <if test="resourceId != null">        and resource_id = #{resourceId,jdbcType=INTEGER}      </if>      <if test="appid != null">       and  appid = #{appid,jdbcType=TINYINT}      </if>      <if test="resourceUrl != null">       and  resource_url = #{resourceUrl,jdbcType=VARCHAR}      </if>      <if test="resourceDesc != null">       and  resource_desc = #{resourceDesc,jdbcType=VARCHAR}      </if>    </trim>  </select>

The third way is the most recommendable mode, the trim tags in tag the labels are prefixed with where, namely where words. The back of the prefixOverrides= "and|or" is that if the beginning contains where tags in the content is and or or, and or or so long ignored. There is another: suffixOverrides= "and|or", said where and or at the end of sentence or ignore and or or.

1)ID must be the name and function of mapper.java in the same 2) note that the original format of the SQL statement, Remove if tags also if a correct statement 3) trim statement can contain the prefix and suffix, Prefix prefix, The suffix suffix, The header contains certain content coverage, That is ignored, Can also put some end cover, The corresponding properties are prefixOverrides and suffixOverrides; because trim has such a function, So we can also use trim very simple functions instead of where elements

The original blog address:
http://jingyan.baidu.com/article/af9f5a2dd8143b43140a4520.html
On how to dynamically access through the sshpass log file please see the article below.
http://jingyan.baidu.com/article/cd4c2979ca556c756e6e60aa.html
The file md5sun to generate MD5 how to use Linux in Java
http://jingyan.baidu.com/article/cd4c2979ca556c756e6e60aa.html
[/size][/size][/size][/size]
Compared with other values of null MySql database value
http://jingyan.baidu.com/article/9113f81b2adc882b3214c7cb.html
Java programming experience sharing of Map use
http://jingyan.baidu.com/article/215817f7d9d6b31eda1423d8.html
The experience of using MySql -- through the in query how scheduling problem
http://jingyan.baidu.com/article/67662997325ccf54d51b84d5.html
The experience of using Mybatis XML note
http://jingyan.baidu.com/article/fec7a1e51d7b451190b4e729.html
Mybatis using batch experience sharing operation
http://jingyan.baidu.com/article/11c17a2c7f376af446e39d21.html
MyBatis uses query experience sharing
http://jingyan.baidu.com/article/af9f5a2dd8143b43140a4520.html
Linux how to build Tomcat server
http://jingyan.baidu.com/article/3052f5a1d93c1497f31f860d.html
How to query data with the Linux script
http://jingyan.baidu.com/article/2c8c281dfb0add0008252a04.html
Linux sshpass programming experience, md5sum, ssh
http://jingyan.baidu.com/article/cd4c2979ca556c756e6e60aa.html
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Augus at December 09, 2013 - 6:36 AM