自定义Mapper文件的几种写法
2016-12-15 10:16
429 查看
1.为xml中某些特殊符号作转义
1.1不含有动态语句(where,if)
1.2含有动态语句(where,if)
<select id="getAccountErrorCount" resultType="int" parameterType="map">
select count(*) from t_acctreg_accounterror
<where>
<if test="enddate != null and enddate != ''">
<![CDATA[createdate <= #{enddate}]]>
</if>
<if test="acctno != null and acctno != ''">
<![CDATA[AND acctno LIKE '%'||#{acctno}||'%']]>
</if>
</where>
</select>
2.不指定jdbc类型的参数,MyBatis默认为Other类型。当不指定jdbc类型时,若参数为null,将报错Error setting null parameter. Most JDBC drivers require
that the JdbcType must be specified for all nullable parameters。
下面是MyBatis中常用的javaType和jdbcType的对应关系
javaType jdbcType
String CHAR
String VARCHAR
BigDecimal DECIMAL
BigDecimal NUMERIC
boolean BOOLEAN
byte TINYINT
short SMALLINT
int INTEGER
long BIGINT
float FLOAT
double DOUBLE
Date DATE
Time TIME
Timestamp TIMESTAMP
Clob CLOB
Blob BLOB 大致是相对应地改为全部大写。
1.1不含有动态语句(where,if)
<select id="getAccountsByBranch" resultType="Account" parameterType="string"> <![CDATA[SELECT * FROM t_acctreg_accounts where acctno < #{acctno}]]> </select>
1.2含有动态语句(where,if)
<select id="getAccountErrorCount" resultType="int" parameterType="map">
select count(*) from t_acctreg_accounterror
<where>
<if test="enddate != null and enddate != ''">
<![CDATA[createdate <= #{enddate}]]>
</if>
<if test="acctno != null and acctno != ''">
<![CDATA[AND acctno LIKE '%'||#{acctno}||'%']]>
</if>
</where>
</select>
2.不指定jdbc类型的参数,MyBatis默认为Other类型。当不指定jdbc类型时,若参数为null,将报错Error setting null parameter. Most JDBC drivers require
that the JdbcType must be specified for all nullable parameters。
下面是MyBatis中常用的javaType和jdbcType的对应关系
javaType jdbcType
String CHAR
String VARCHAR
BigDecimal DECIMAL
BigDecimal NUMERIC
boolean BOOLEAN
byte TINYINT
short SMALLINT
int INTEGER
long BIGINT
float FLOAT
double DOUBLE
Date DATE
Time TIME
Timestamp TIMESTAMP
Clob CLOB
Blob BLOB 大致是相对应地改为全部大写。
相关文章推荐
- Hadoop基于WordCount的Mapper、Reducer、Combiner、Partitioner和自定义多文件输出
- 使用storyBoard和使用自己的xib文件的几种写法分析
- MyBatis中Mapper.xml文件中关于字符串的判断写法(已经验证好用)
- 类加载器加载配置文件的几种写法
- Git 忽略文件规则:.gitignore文件的几种写法
- 关于linux下自定义的 alias文件和自定义函数库的通用写法(只适合自己的)
- Lightswitch C1FLexGrid 自定义列显示格式的几种写法
- mybatis-generator扩展教程系列 -- mapper xml文件增加自定义sql
- java项目中程序加载配置文件的几种写法
- mybaitis 的 mapper.xml 文件中 参数为List集合SQL 的写法。
- 自定义View的几种写法一
- MyBatis 【Mapper】文件常用写法
- 【ibatis】自定义mapper.xml文件(#与$的详解)
- Mybatis增删改查mapper文件写法
- IDEA中使用自定义的配置文件.properties的路径写法
- 整合maven+mybatis+generator生成java自定义model实体类,dao接口和mapper映射文件
- mybatis映射文件mapper.xml的写法。
- Mybatis增删改查mapper文件写法详解
- 重命名文件的几种写法
- mybatis的mapper配置文件的一般写法。