MyBatis “include refid” and “sql” tags
include refid
The following statements can be made in MyBatis.
<include refid="from" />
Here we use the key from, but it can be anything. This key will include SQL written elsewhere.
<sql></sql>タグ
The way to describe it elsewhere is to use
<sql id="from"> FROM SCHEMA.TBL A </sql>
Below is an example description.
<select id="select_data"> SELECT A.COLUMN <include refid="from" /> <include refid="where" /> </select>
The namespace attribute is assumed to be specified in the mapper XML file, so the refid should be “namespece.refid”.
<?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="jp.co.confrage.repository.EmployeeMapper" > <sql id="colomun_list"> id, name, age </sql> <select id="select_data" > select <include refid="jp.co.confrage.repository.EmployeeMapper.column_list" /> from employee </select> </mapper>
コメント