A little record about Mybatis

1. There are two commonly used parameterTypes of Mybatis, one is the object of the class, and the other is the Map, and the method of taking the value is also very simple:

Basic data type: #{parameter} Get the value in the parameter

Complex data types: #{attribute name}, #{key} in map

2. Let me mention about #{} and ${}. When the former is dynamically parsed, it is understood that this position in sql has become precompiled? , the latter is a bit like the assignment and pasting of strings, the sql statement before pre-compilation no longer contains variables, and it is completely constant.

Then what is to be recorded here is a sql statement related to sorting:

Here I am using MyBatis:

<select id="selectList" parameterType="java.util.Map" resultMap="EditionMap">
        SELECT te.id, te.e_edition_time, tu.u_name, te.e_notes
        FROM t_edition AS te
        LEFT JOIN
        t_user AS tu
        ON te.e_edition_setter_id = tu.id
        WHERE 1=1
        <if test="eTime != null and eTime.trim() != ''">
            and e_edition_time like CONCAT('%',#{eTime,jdbcType=TIMESTAMP},'%')
        </if>
        ORDER BY ${sidx} ${order}
</select>

The last ORDER here, the first use of #{} has not been able to, and then replaced with $, in short, order By, which is followed by a fixed string, use ${}, of course, the others are still Use #{} for a little more benefit!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325015215&siteId=291194637