1. 程式人生 > >Mybatis本人配置出錯解決

Mybatis本人配置出錯解決

1、

Invalid bound statement (not found): com.lion.mapper.OrdersMapperCustom.findUserItems

原因 :select中的id和對應介面中的名稱不匹配導致的。
解決:id名與方法名一致

錯誤:
<select id="findUserItem" resultMap="ItemResultMap">
public List<User> findUserItems()throws Exception;
正確:
<select id="findUserItems" resultMap="ItemResultMap"
> public List<User> findUserItems()throws Exception;

2、

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/lion/mapper/OrdersMapperCustom.xml
### The error occurred while processing mapper_resultMap[OrdersAndOrderDetailResultMap]_collection[orderdetails]
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66) at com.lion.Test.main.main(main.java:24) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error
resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'OrdersAndOrderDetailResultMap'. Cause: java.lang.ClassNotFoundException: Cannot find class: OrdersAndOrderDetailResultMap at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80) ... 2 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'OrdersAndOrderDetailResultMap'. Cause: java.lang.ClassNotFoundException: Cannot find class: OrdersAndOrderDetailResultMap 這個錯誤原因是 resultMap 寫成了 resultType的問題 一定要注意 ,,,自習觀察

原因:這個錯誤原因是 resultMap 寫成了 resultType的問題
解決:將出錯的select標籤中的resultType改成resultMap即可

錯誤:
<select id="findOrdersAndOrderDetailResultMap" resultType="OrdersAndOrderDetailResultMap">
正確:
<resultMap type="com.lion.po.Orders" id="OrdersAndOrderDetailResultMap">
...
</resultMap>

<select id="findOrdersAndOrderDetailResultMap" resultMap="OrdersAndOrderDetailResultMap">