MyBatis: Difference between revisions
Jump to navigation
Jump to search
(7 intermediate revisions by the same user not shown) | |||
Line 133: | Line 133: | ||
| valign="top" | | | valign="top" | | ||
* [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] | ||
* [https://stackoverflow.com/questions/44533937 MyBatis Collections Passing Multiple Columns] | |||
* [https://programmer.group/integration-of-mybatis-and-jpa-persistence-in-springboot-learning-6.html Integration of MyBatis & JPA in Spring boot] | |||
* [https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples/paging MyBatis Dynamic SQL for Paging] | * [https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples/paging MyBatis Dynamic SQL for Paging] | ||
* [https://mybatis.org/mybatis-dynamic-sql/docs/select.html MyBatis Dynamic SQL for Select] | * [https://mybatis.org/mybatis-dynamic-sql/docs/select.html MyBatis Dynamic SQL for Select] | ||
* [https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples MyBatis Dynamic SQL Examples] | * [https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples MyBatis Dynamic SQL Examples] | ||
* [https://github.com/mybatis/typehandlers-jsr310#supported-types MyBatis Supported Types] | |||
* [[MapStruct]] | |||
* [[Lombok]] | |||
| valign="top" | | |||
* [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html Java » ISO <code>DateTimeFormatter</code>] | |||
|} | |} |
Latest revision as of 18:06, 1 February 2024
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);
}
}