首页 新闻 赞助 找找看

求问:关于mybatis常见出错的问题

0
悬赏园豆:10 [已解决问题] 解决于 2017-10-06 21:58

### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 84; columnNumber: 10; 元素类型为 "mapper" 的内容必须匹配 "(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+"

 

这里附上我的表映射XML文档:

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <mapper namespace="com.chen.dao.GoodsDao2">
 6 
 7 
 8   <select id="selAll" resultType="com.chen.GoodsInfo">
 9     select * from goods 
10   </select>
11   
12   <select id="selOne" resultType="com.chen.GoodsInfo">
13     select * from goods where id = #{id}
14   </select>
15   
16   <!-- 新增 -->
17   <!-- #{} 里填的是 对象的属性值,不能随便写-->
18   <insert id ="insertGoods">
19   insert into goods(id,name) values(#{id},#{name});
20   </insert>
21   
22   <!-- 修改 -->
23   <update id="updateGoods">
24       update goods set name =#{name} where id =#{id};
25   </update>
26   
27   <!-- 删除 -->
28   <delete id= "deleteGoods">
29       delete from goods where id =#{id}
30   </delete>
31   
32   <!-- 多条件查询,传入多个参数。String name,char id -->
33   <!-- 切记,标签id要与接口方法名相同,不然报错 -->
34   <!-- 凡是查询语句,千万别忘记写resultType(返回结果类型) -->
35   <select id="querylist" resultType="com.chen.GoodsInfo">
36      <!-- 
37           #{}默认采用预处理的方式去处理SQL语句。。。
38           ${}是采用非预处理模式来处理数据。。 
39      -->
40           select * from goods  where name like '${param1}%' and id=#{param2}
41     </select>
42     
43   <select id="querylist2" resultType="com.chen.GoodsInfo">
44     select * from goods  where name like '${name}%' and id=#{id}
45     
46   </select>
47     
48     <!-- 下面是动态SQL -->
49   <select id="queryByIf" resultType="com.chen.GoodsInfo">
50         select * from goods where 
51         <if test="name !=null">
52             name like '${name}%'
53         </if>
54    </select>
55     
56    <select id="queryByChoose" resultType="com.chen.GoodsInfo">
57         select * from goods where 
58         <choose>
59             <when test="name !=null">
60                 name like '${name}%'
61             </when>
62             
63             <when test="id !=null">
64                and id =${id}
65             </when>
66             
67             <otherwise>
68                 order by name
69             </otherwise>
70         </choose>
71    </select>
72     
73<select id="queryByTrim" resultType="com.chen.GoodsInfo">
74         select * from goods 
75         <trim prefix="where" prefixOverrides="AND | OR">
76             <if test="name !=null">
77                  name like '${name}%'
78             </if>
79             <if test="id !=null">
80                   and id =${id}
81             </if>
82         </trim >
83    </select>
84 </mapper>     
85  
Pororo的主页 Pororo | 初学一级 | 园豆:192
提问于:2017-10-05 15:55
< >
分享
最佳答案
0

七十三行前面多了一个逗号哦

收获园豆:10
吉吉的城 | 小虾三级 |园豆:566 | 2017-10-05 23:03

正解哦,好细心

Pororo | 园豆:192 (初学一级) | 2017-10-06 21:56
其他回答(1)
0

resultType对应的是基本类型的返回值,你这里select * 应该使用resultMap才对

何甜甜在吗 | 园豆:357 (菜鸟二级) | 2017-10-06 21:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册