Mybaitis配置总结
- 在mybatis-config.xml中配置分页插件,插件配置必须放在mapper前面
<plugins>
<plugin interceptor="com.rrtong.frame.dao.PaginationInterceptor">
<property name="dialect" value="oracle"/>
</plugin>
</plugins>
- Mybatis分页拦截器获取sql
/*以下得到的是要执行的sql语句,并不是配置的sql语句*/
StatementHandler statementHandler = (StatementHandler)invocation.getTarget();
BoundSql boundSql = statementHandler.getBoundSql();
String originalSql = boundSql.getSql();
- 出现java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction(Ljava/sql/Connection;)Lorg/apache/ibatis/transaction/Transaction;
版本不正确,需要使用更高版本的 mybatis-spring
https://mybatis.googlecode.com/files/mybatis-spring-1.2.1.zip
- Mybaitis参数严格区分大小写
mybatis 配置文件中的参数绑定区分大小写,必须与传递的参数名保持一致
- 出现数据类型111时,这是因为数据库字段数据类型与entity中的字段定义的数据类型不一致导致的,有以下两种方法解决
1、设定entity的数据类型与数据库类型一致
2、在sql中定义参数的数据类型,比如
where userCode = #{userCode, jdbcType=VARCHAR}
- 实现数据库字段与实体字段的关系对应
<resultMap id="Archive" type="Archive">
<id column="ARCHIVESKEY" property="archiveKey" />
<result column="title" property="archiveTitle" />
</resultMap>
- 定义oracle数据库的mybatis获取主键并返回的配置,mybatis before after设置
<p> <selectKey keyProperty="archiveKey" order="BEFORE" resultType="String">
SELECT SEQ_ARCHIVE.NEXTVAL
FROM DUAL
</selectKey></p>
- 定义其他数据库的Mybatis获取主键并返回的配置
<insert id="insertUser" useGeneratedKeys="true" keyProperty="userId" parameterType="com.mybatis.User">
insert into user(userName,password)
values(#{userName},#{password})
</insert>
- 定义mybatis查询结果注入到实体中
<resultMap id="Archive" type="Archive">
<id column="SPAARCHIVESKEY" property="archiveKey" />
<result column="title" property="archiveTitle" />
</resultMap> <select id="getArchive" parameterType="HashMap" resultMap="Archive">
select
SPAARCHIVESKEY,
TITLE
from Archives
where USERCODE = #{userCode, jdbcType=VARCHAR}
And VALID= #{valid, jdbcType=VARCHAR}
</select>
- 定义Mybaitis更新数据库表记录
<update id="updateArchive" parameterType="Archive">
update Tbl_ARCHIVES
set
title = #{archiveTitle},
content = #{content},
feeValue = #{feeValue}
security = #{security},
subjectType = #{subjectType},
gradeType = #{gradeType},
gather = #{gather},
archiveType = #{archiveType},
keyWordName = #{keyWordName}
where archivesKey = #{archiveKey}
</update>
- 定义mybatis删除数据表记录的方式
<delete id="deleteArchive" parameterType="String">
delete from title
where spaArchivesKey = #{archiveKey}
</delete>
- 定义公共的sql语句,允许复用
<sql id="addrColumn">
a.PUSH_ID,
a.MEMBER_ID,
a.CONTENT,
a.PHOTO,
a.PUSH_NAME,
a.IS_AUTO,
a.IS_FINE,
a.IS_SOURCE,
a.SOURCE_PUSH_ID,
DATE_FORMAT(a.CREATE_TIME,'%Y-%m-%d %H:%i:%s') CREATE_TIME,
DATE_FORMAT(a.DELETE_TIME,'%Y-%m-%d %H:%i:%s') DELETE_TIME
</sql>
引用复用的sql语句
<select id="getMyOrFineBlog" parameterType="MicroBlog" resultType="MicroBlog">
SELECT
<include refid="addrColumn"/>
FROM TBL_BLOG_PUSH a, TBL_USER_MEMBER b
WHERE a.MEMBER_ID = b.MEMBER_ID
<if test="isFine == 1"> AND a.IS_FINE = #{isFine} </if>
</select>
Mybaitis配置总结的更多相关文章
- mybaitis配置信息
在配置mybatis当中,jdbcType的名称要大写,时间类型DATE只能传入年月日,要想传入时分秒,应该使用TIMESTAMP http://www.blogjava.net/hello-yun/ ...
- 01-电子商城项目介绍及ssm框架搭建
1.B2C电商项目功能及架构 1.1功能列表 1.2系统架构(soa架构) 2.后台管理系统工程搭建及测试 ypMall,ypMall-manager-web ypMall为父项目,管理子项目的jar ...
- Spring、SpringMVC、Mybaitis框架配置
给大家推荐2个网址,介绍的非常详细 SSM环境搭建 http://blog.csdn.net/zhshulin/article/details/37956105 SSM代码生成工具介绍 http:// ...
- java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化
一.ssm框架搭建 1.1创建项目 新建项目后规划好各层的包. 1.2导入包 搭建SSM框架所需包百度云链接:http://pan.baidu.com/s/1cvKjL0 1.3整合spring与my ...
- 缓存策略 半自动化就是mybaitis只支持数据库查出的数据映射到pojo类上,而实体到数据库的映射需要自己编写sql语句实现,相较于hibernate这种完全自动化的框架我更喜欢mybatis
springboot入门(三)-- springboot集成mybatis及mybatis generator工具使用 - FoolFox - CSDN博客 https://blog.csdn.net ...
- spring mvc整合mybaitis和log4j
在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...
- IDEA 安装配置及操作总结(新手必看)
Jetbrains官网下载IDEA15 我们在浏览器输入网址https://www.jetbrains.com/.选择相应的系统版本,下载最新版本的IDEA15,Windows系统双击安装文件,根据界 ...
- 配置android sdk 环境
1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/
- Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记
以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...
随机推荐
- POJ3984 迷宫问题
典型BFS. #include <iostream> #include <memory.h> #include <queue> #include <map&g ...
- [wikioi]最优布线问题
http://wikioi.com/problem/1231/ Kruskal+并查集.comp函数里面如果用const引用的话,可以减少copy.并查集find的时候是递归找父亲的根.无他. #in ...
- message 匹配不上grok正则 也会写入到elasticsearch
{ "message" => "scan test 20161201", "@version" => "1" ...
- android使用tabhost实现导航
参考 http://blog.csdn.net/xixinyan/article/details/6771341 http://blog.sina.com.cn/s/blog_6b04c8eb0101 ...
- 深入Android开发之--理解View#onTouchEvent
一:前言 View是Android中最基本的UI单元. 当一个View接收到了触碰事件时,会调用其onTouchEvent方法.方法声明如下: ? 1 2 3 4 5 6 7 /** * Imple ...
- efront二次开发记要
efront系统是一套开源的在线学习系统,是用PHP编写的,内含“考试”功能.该系统的开源的是社区版,虽然看上去功能强大,但使用起来却很不符合国情.为了让公司使用,先做了一次最简化的二次开发,由于是最 ...
- [DP] LCS小结
额..失误.. LCS是Longest Common Subsequence的缩写,即最长公共子序列.一个序列,如果是两个或多个已知序列的子序列,且是所有子序列中最长的,则为最长公共子序列. DP.O ...
- Windows SharePoint Services 3.0编码开发工具和技巧(Part 1 of 2)
转:http://blog.csdn.net/mattwin/article/details/2074984 WSSv3 Technical Articles_Windows SharePoint S ...
- Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
1: /// <summary> 2: /// Write an algorithm such that if an element in an MxN matrix is 0, it ...
- 51单片机产生1Hz-5kHz可调占空比方波
学校的课程设计,总结一下. 注意 1.高低电平的改变不适合在主函数的while循环中,因为要有数码管动态显示的延时和其它逻辑处理,时间太长会不能及时改变高低电平值. 2.中断的执行时间一定是不能超过定 ...