[JAVA] MyBatis memorandum

I will write a memorandum of MyBatis.

IF statement
<if test="(author != null and author.name != '') or authorList.size() > 0">
</if>
IN clause
column in
<foreach item="sample" open="(" close=")" collection="sampleList" separator=",">
  #{sample}
</foreach>
When using the inequality sign "<"
<![CDATA[
  column <= #{parameter}
]]>
When binding a parameter as a DATE type
column = #{parameter,jdbcType=DATE}

include

<sql id="sample">
  column = True
<sql>

<select id="xxxxx" resultType="string">
  select column from table where <include refid="sample" />
</select>

resultType

If the result is a List, resultType specifies the type of the contents of the List. If you want to get it as List \ type, write resultType = "string".

Bulk Insert

<insert id="xxxxx" parameterType="java.util.List">
  insert into table(column,・ ・ ・) values
  <foreach collection="list" item="item" separator=",">
  ( #{item.propertyName}, #{item.propertyName},・ ・ ・)
  </foreach>
</insert> 

Bulk Update

<update id="xxxxx" parameterType="java.util.List">
  <foreach collection="list" item="item" separator=";">
  update table set column = #{item.propertyName} where column = #{item.propertyName}
  </foreach>
</update> 

jdbcType

jdbcType java
VARCHAR String
INTEGER int
NUMERIC BigDecimal
BIT boolean
DATE Date
TIMESTAMP Date
alias

"java.lang.String" can be written as "string". http://www.mybatis.org/mybatis-3/ja/configuration.html#typeAliases

How to specify parameters of Java Mapper interface
void select(
        @Param("param1") String param1,
        @Param("param2") List<String> param2);

For Mapper XML, write parameterType = "map".

How to create a search condition (Criteria)
TableExample example = new TableExample();
example.createCriteria()
        .andColumnEqualTo(value)
        .andColumnEqualTo(value);

example.setOrderByClause("column DESC, column ASC");

Recommended Posts

MyBatis memorandum
memorandum
memorandum
Java memorandum
Rails memorandum
Error memorandum
Jaba Jaba Memorandum
MyBatis story
JavaFx memorandum
JAVA memorandum
JUnit memorandum
Docker memorandum
Gradle Memorandum
Docker memorandum
thymeleaf memorandum
Technical memorandum (Docker)
Log Level Memorandum
Memorandum docker command
Disable MyBatis3 cache
Apache FreeMarker memorandum
MyBatis string comparison
Java memorandum (list)
Screen transition memorandum
Rails tutorial memorandum 1
[Ruby] Method memorandum
Rails tutorial memorandum 2
Docker command memorandum
Java study memorandum
Spring Boot Memorandum
[Java] Optional memorandum
Memorandum (Spring Web)