ibatis

简单实现ibatis的物理分页

最后都变了- 提交于 2019-12-03 04:24:56
本文是原创文章,转载请注明出处: http://my.oschina.net/fqt/blog/52431 一直以来ibatis的分页都是通过滚动ResultSet实现的,应该算是逻辑分页吧。逻辑分页虽然能很干净地独立于特定数据库,但效率在多数情况下不及特定数据库支持的物理分页,而hibernate的分页则是直接组装sql,充分利用了特定数据库的分页机制,效率相对较高。 网上已有 《使ibatis支持hibernate式的物理分页》等类似的文章以 继承 SqlExecutor的方式 实现了物理分页, 但是 侵入性非常强,还得实现数据库方言 ,方法非常复杂。同时 SqlExecutor不是接口,对它的方法继承也不能保证版本稳定。本文中将介绍的方式是实现queryWithSqlHandler方法,在查询前将通过SqlHandler接口把sql传给调用者,再用处理后的sql进行最终查询,从而实现物理分页等功能: //用queryWithSqlHandler方法实现物理分页的例子: public Page queryPage(String statementId, param, final Page page){ final int pageNum = page.getPageNum(); final int pageSize = page.getPageSize(); List list

Mybatis XML vs Annotation

限于喜欢 提交于 2019-12-03 03:07:23
I have read the book and documentation about Mybatis, both XML and Annotation does what I want, but from myBatis official website, they claim XML is a better way of doing Mappers, because Java annotation has limitations. I personally prefer Annotations e.g public interface PersonDAO { String INSERT_PERSON = "insert into person (title,firstName,surName,jobTitle,dob,email,mobile,landPhone,fax,twitter,facebook,linkedin) VALUES (#{title},#{firstName},#{surName},#{jobTitle},#{dob},#{email},#{mobile},#{landPhone},#{fax},#{twitter},#{facebook},#{linkedin})"; String UPDATE_PERSON = "update person set

采用SpringBoot整合Mybatis框架插入数据时报错及解决

自作多情 提交于 2019-12-03 03:06:52
这两天做SpringBoot整合Mybatis项目的时候,插入时报错: 3:45:59.936 DEBUG [http-nio-8080-exec-8] o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver 133 - Resolving exception from handler [public java.lang.String com.yooli.sale.html.controller.reduce.ReduceController.saveApply()]: java.lang.RuntimeException: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yooli.sale.dao.reduce.ReduceMapper.insert org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yooli.sale.dao.reduce.ReduceMapper.insert at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>

was not registered for synchronization because synchronization is not active

我的未来我决定 提交于 2019-12-03 02:16:46
转: SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4529fa91] 2018-12-25 13:41:00 木林森淼 阅读数 13904 更多 分类专栏: Mybatis 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/yangfengjueqi/article/details/85246411 控制台日志如下 DEBUG - Creating a new SqlSession DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@ 4529fa91] was not registered for synchronization because synchronization is not active DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@ 4529fa91] 并没有看出错误原因是什么,可以断定是SQL语句那里的

Hibernate Vs iBATIS [closed]

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For our new product re-engineering, we are in the process of selecting the best framework from Java. As the consideration is to go for database agnostic approach for model, we are working on options between Struts + Spring with iBATIS or Hibernate. Please advice which is best as both offer persistence. 回答1: Ibatis and Hibernate are quite different beasts. The way I tend to look at it is this: Hibernate works better if your view is more object-centric . If however you view is more database-centric then Ibatis is a much stronger choice. If you

Iterate list of Objects in Ibatis

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a list of object where I want to iterate and access a particular field in ibatis sql. Ex. public Class Student { String id ; String name ; } I will pass as parameter a List of Student object(List(Student)) and do iteration accessing the id for each object bean. How do I do this? 回答1: The foreach -tag is what you are looking for. Example: SELECT * FROM POST P WHERE ID in #{item} See the user guide for more info, chapter "dynamic sql". By the way, iBatis is no longer developed and is frozen, it is now called "MyBatis" and the

mybatis: Using mapper interfaces with XML config for global parameters

≡放荡痞女 提交于 2019-12-03 00:49:33
I like the XML notation for specifying global parameters such as connection strings. I also like Mapper annotations. When I try to combine the two, I get this exception . Is there a way to combine the two? I would like to use an XML file for the global configurations, but have mybatis take Mapper interfaces into account. The problem is that SqlSessionFactoryBuilder().build() takes either a Reader (which I want to use to pass the XML config), or a Configuration object (which I see has the addMappers() method that can help me) - but I don't understand how to combine the two. Atilio Ranzuglia

Spring Boot中报错org.apache.ibatis.binding.BindingException: Parameter &#039;XXXX&#039; not found. Available parameters are [0, 1, param1, param2]的解决办法

匿名 (未验证) 提交于 2019-12-03 00:40:02
我这里的报错信息显示: org.apache.ibatis.binding.BindingException: Parameter ‘reqUsername‘ not found. Available parameters are [0, 1, param1, param2] 原因:当只有一个参数时,Mapper中可以不使用@Param,但是当有多个参数的时候,要使用@Param。 原来的代码: @Select("select * from tz_user where " + GlobalConfigure.USER_AUTH_SQL_SUFFIX) List<User> getAllUser(String reqUsername, String reqPasswd); 改成: @Select("select * from tz_user where " + GlobalConfigure.USER_AUTH_SQL_SUFFIX) List<User> getAllUser(@Param("reqUsername") String reqUsername, @Param("reqPasswd") String reqPasswd); 就成功返回结果了。 原文:https://www.cnblogs.com/zifeiy/p/9279121.html

项目切换为K8S后,数据库连接出现异常

a 夏天 提交于 2019-12-03 00:29:37
项目切换为K8S的时候访问出现异常,路过的伙伴可以帮忙分析一下哈: Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database! ### The error may exist in class path resource [firsthand-core-sqlmap/cdm/YlQuarzRegisterPHKXMapper.xml] ### The error may involve com.yooli.cdm.dao.YlQuarzRegisterPHKXMapper.selectIsSuccess ### The error occurred while executing a query ### Cause: org.springframework

支付宝面试题

匿名 (未验证) 提交于 2019-12-03 00:22:01
简单的介绍一下你的项目   一个有500个用户的广播系统,你怎么做性能优化   当用户提交请求后,却立即按撤回按钮,涉及性能的数据落地问题你怎么处理   Lucene底层实现原理,它的索引结构   ibatis跟hibernate的区别   ibatis是怎么实现映射的,它的映射原理是什么   JavaI/O底层细节,注意是底层细节,而不是怎么用   你对mysql有什么了解   说一下数据库事务的四个特性,为什么mysql事务能保证失败回滚   mysql数据库的锁有多少种,怎么编写加锁的sql语句   mysql什么情况下会触发表锁   页锁、乐观锁、悲观锁   tcp三次握手的过程   进程跟线程的区别   redis的操作是不是原子操作   ArrayList跟LinkedList的底层实现原理,使用场景   B+树   一道算法题,在一个整形数组中,有正数有负数,找出和最大的子串   动态规划的思想 文章来源: 支付宝面试题