在mybatis-config.xml中配置分页插件,插件配置必须放在mapper前面
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}
实现数据库字段与实体字段的关系对应
定义oracle数据库的mybatis获取主键并返回的配置,mybatis before after设置
select seq_archive.nextval from dual
定义其他数据库的mybatis获取主键并返回的配置
insert into user(username,password) values(#{username},#{password})
定义mybatis查询结果注入到实体中
select spaarchiveskey, title from archives where usercode = #{usercode, jdbctype=varchar} and valid= #{valid, jdbctype=varchar}
定义mybaitis更新数据库表记录
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}
定义mybatis删除数据表记录的方式
delete from title where spaarchiveskey = #{archivekey}