MyBatis: Difference between revisions
Jump to navigation
Jump to search
Line 133: | Line 133: | ||
| valign="top" | | | valign="top" | | ||
* [https://programmer.group/integration-of-mybatis-and-jpa-persistence-in-springboot-learning-6.html Integration of MyBatis & JPA in Spring boot] | |||
* [https://stackoverflow.com/questions/27952472 Serialize/deserialize <code>java.time</code> with Jackson] | * [https://stackoverflow.com/questions/27952472 Serialize/deserialize <code>java.time</code> with Jackson] | ||
* [https://stackoverflow.com/questions/17193040 MyBatis Association Passing Multiple Columns] | * [https://stackoverflow.com/questions/17193040 MyBatis Association Passing Multiple Columns] |
Revision as of 00:19, 8 October 2020
Sql
<sql id="userColumns">
${alias}.id,
${alias}.entered,
${alias}.enterer,
${alias}.amended,
${alias}.amender
</sql>
<select id="selectUsers" resultType="map">
SELECT
<include refid="userColumns"><property name="alias" value="t1"/></include>,
<include refid="userColumns"><property name="alias" value="t2"/></include>
FROM
M00TM00X00 t1
LEFT join M00TM00X00 t2 on t1.id = t2.id
</select>
Key
<insert id="createDataType">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
SELECT
nvl(MAX(id),0) + 1 id
FROM
M00TM00X00
</selectKey>
INSERT INTO M00TM00X00 (
id,
data_type_code,
data_type_name,
entered,
enterer
)
VALUES (
#{id},
#{dataTypeCode},
#{dataTypeName},
SYSDATE,
'SELF'
)
</insert>
JdbcType
package org.apache.ibatis.type;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
/**
* @author Clinton Begin
*/
public enum JdbcType {
ARRAY(Types.ARRAY),
BIT(Types.BIT),
TINYINT(Types.TINYINT),
SMALLINT(Types.SMALLINT),
INTEGER(Types.INTEGER),
BIGINT(Types.BIGINT),
FLOAT(Types.FLOAT),
REAL(Types.REAL),
DOUBLE(Types.DOUBLE),
NUMERIC(Types.NUMERIC),
DECIMAL(Types.DECIMAL),
CHAR(Types.CHAR),
VARCHAR(Types.VARCHAR),
LONGVARCHAR(Types.LONGVARCHAR),
DATE(Types.DATE),
TIME(Types.TIME),
TIMESTAMP(Types.TIMESTAMP),
BINARY(Types.BINARY),
VARBINARY(Types.VARBINARY),
LONGVARBINARY(Types.LONGVARBINARY),
NULL(Types.NULL),
OTHER(Types.OTHER),
BLOB(Types.BLOB),
CLOB(Types.CLOB),
BOOLEAN(Types.BOOLEAN),
CURSOR(-10), // Oracle
UNDEFINED(Integer.MIN_VALUE + 1000),
NVARCHAR(Types.NVARCHAR), // JDK6
NCHAR(Types.NCHAR), // JDK6
NCLOB(Types.NCLOB), // JDK6
STRUCT(Types.STRUCT),
JAVA_OBJECT(Types.JAVA_OBJECT),
DISTINCT(Types.DISTINCT),
REF(Types.REF),
DATALINK(Types.DATALINK),
ROWID(Types.ROWID), // JDK6
LONGNVARCHAR(Types.LONGNVARCHAR), // JDK6
SQLXML(Types.SQLXML), // JDK6
DATETIMEOFFSET(-155), // SQL Server 2008
TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), // JDBC 4.2 JDK8
TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); // JDBC 4.2 JDK8
public final int TYPE_CODE;
private static Map<Integer,JdbcType> codeLookup = new HashMap<>();
static {
for (JdbcType type : JdbcType.values()) {
codeLookup.put(type.TYPE_CODE, type);
}
}
JdbcType(int code) {
this.TYPE_CODE = code;
}
public static JdbcType forCode(int code) {
return codeLookup.get(code);
}
}