Tag: mybatis

在myBatis 中传递多个列

我想知道,我们如何在myBatis关联标记中传递多个列。 例如,我在一个mapper.xml文件中有以下xml片段: 如您所见,带有property订阅的只有一列, course_id 我想传递2列,因此产生的代码,我们如何做到这一点? 我尝试了以下组合,没有效果: column=”{course_id,user_id}” // null,null are passed as parameters column=”course_id,user_id” // null,null are passed as parameters column=”{COURSE_ID=course_id,USER_ID=user_id}” // null,null are passed as parameters 但如果我传递单个,column =“{course_id}”或column =“course_id” 工作没有任何问题。 任何想法的家伙?

Mybatis XML与注释

我已经阅读了有关Mybatis的书和文档,XML和Annotation都做了我想要的,但是从myBatis官方网站,他们声称XML是一种更好的做Mappers的方法,因为Java注释有局限性。 我个人更喜欢注释,例如 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 title=#{title},firstName=#{firstName},surName=#{surName},jobTitle=#{jobTitle},dob=#{dob},email=#{email},mobile=#{mobile},landPhone=#{landPhone},fax=#{fax},twitter=#{twitter},facebook=#{facebook},linkedin=#{linkedin} where id=#{id}”; String GET_PERSON_BY_ID = “SELECT * FROM vw_person WHERE id = #{personId}”; String DELETE_PERSON = “DELETE FROM person WHERE id = #{personId}”; @Select(GET_PERSON_BY_ID) public PersonVO doSelectPerson(long personId) throws Exception; @Update(UPDATE_PERSON)@Options(flushCache = true, […]

使用mybatis“MapperRegistry不知道类型接口”exception

我正在使用注释设置mybatis,并获得这个有用的例外 org.apache.ibatis.binding.BindingException:MapperRegistry不知道类型接口org.foo.Bar 谷歌搜索没有找到任何东西,也没有找到用户指南。 我错过了什么?

使用mybatis进行Java 8 LocalDate映射

我使用java.time.LocalDate(Java 8)来表示Java类中的一些成员字段。 class Test{ private LocalDate startDate; private LocalDate endDate; //other fields //getters and setters } 我也在使用mybatis来与我的数据库进行交互。 在从数据库中检索某些数据时,所有其他字段都会正确填充,但startDate和endDate字段最终为null。 但是,如果我使用java.util.Date,就像在 private Date startDate; private Date endDate; 当我将它们声明为java.util.Date时,我得到在这两个字段(startDate和endDate)中检索到的正确值。 是因为mybatis目前没有将’Timestamp’(SQL Server)映射到java.time? 我应该如何使用java.time.LocalDate与MyBatis进行映射?

APPARENT DEADLOCK为未分配的待处理任务创建紧急线程

我正在使用mybatis的mysql,我在我们的实时服务器上问候这个错误 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@6538f8f2 — APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 由于我的C3P0设置,我不明白为什么会出现这个错误? 我的C3P0设置是这样的 —-开始更新—– 下面是我的spring-servlet.xml配置 我将 datasource bean 更新为 从我的Dao类中我称之为mapper方法 myDao.updateRecords() 这是我的服务类方法 @Override public List selectAllUsersDetail(long groupId, List ids) { List usersDetailList = null; try { usersDetailList = userDao.selectAllUsersDetail(groupId, ids); } catch (Exception e) { e.printStackTrace(); } return usersDetailList; } 在Dao类我只是注入映射器。 @Resource private UserMapper […]

mybatis:使用带有XML配置的mapper接口来获取全局参数

我喜欢XML表示法来指定连接字符串等全局参数。 我也喜欢Mapper注释。 当我尝试将两者结合起来时,我得到了这个例外 。 有没有办法将两者结合起来? 我想使用XML文件进行全局配置,但mybatis会考虑使用Mapper接口。 问题是SqlSessionFactoryBuilder()。build()需要一个Reader(我想用它来传递XML配置),或者一个Configuration对象(我​​看到它有addMappers()方法可以帮助我) – 但我不明白如何将两者结合起来。

MyBatis枚举用法

我知道之前已经问过这个问题,但是根据我到目前为止找到的信息,我无法实现解决方案。 所以也许有人可以向我解释。 我有一张桌子“状态”。 它有两列:id和name。 id是PK。 我想使用枚举,而不是使用POJO状态。 我创建了如下枚举: public enum Status { NEW(1), READY(2), CLOSED(3); private int id; public void setId(int id) { this.id = id; } public int getId() { return this.id; } Status(int id) { this.id = id; } } 这是我的映射器 SELECT ls.id, ls.name FROM status AS ls WHERE ls.name = #{name} 但由于某种原因,当我尝试检索枚举时,某些东西会中断,但不会抛出任何exception。

如何使用iBatis将数组写入Oracle 10g XE数据库?

我已经找到了这个高低的答案,但无法得到答案。 基本上我有一个使用iBatis写入数据库的对象。 这适用于原始类型,如字符串,int等,但我的对象的一个​​属性是其他对象的数组。 我希望能够持久保存,然后调用’selectById’语句并检索包括数组在内的完整对象。 这是我到目前为止的代码: Mapper.xml insert into TESTTABLE ( ORDERID, MAXPX, COMMISSION, ACCOUNTGRP ) values ( #orderID#, #maxPx#, #commission#, #accountGrp# ) accountGrp是我的数组,但它当前抛出错误。 没有这个字段,该声明工作正常。 java就像这样: public static void insertTrade (Trade obj) throws SQLException { logger.debug(“inserting trade. Order Id: ” + obj.toString()); sqlMapper.insert(“insertTrade”, obj); } 在此先感谢您的帮助!!

ibatis spring java.lang.NoSuchMethodError com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse

我在weblogic 10.3.6中使用spring 3.2.0和ibatis 2.3.4,同时在weblogic中部署。 我得到这个NoSuchMethodError如下: User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘gatewayService’ defined in ServletContext resource [/WEB-INF/applicationContext-granite-webservice.xml]: Cannot resolve reference to bean ‘daoIPInventory’ while setting bean property ‘dao’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘daoIPInventory’ defined in ServletContext resource [/WEB-INF/applicationContext-ip-ibatis-db.xml]: Cannot resolve reference to bean ‘sqlMapClient’ while […]

如何使用MyBatis调用Oracle数据库序列号?

我想通过使用MyBatis从我的Oracle数据库10g中调用序列号,但我只收到如下错误消息: ORA-02289: Sequence is not available. 如何从Oracle数据库中调用序列号? 以下是关于当前MyBatis版本的Maven Project Dependency: org.mybatis mybatis-spring 1.1.1 这是我的Dao Java类: long mySeqNumber = myDaoClass.getNewNumber(); // here I get an exception 这是我的xml声明: SELECT mySeq.nextval FROM dual