The entity name must immediately follow the '&' in the entity reference.

 

 

在mybatis的mapper.xml文件中编写了一段SQL语句如下:

 

我编写的SQL如下:

<!-- 根据角色ID、角色类型、用户ID查询出角色列表-->
	<select id="getUsersByRoleAuthorize" resultMap="RoleResultMap">
		SELECT 	
			u.USER_ID, 
			u.user_name,
			u.user_status,
			ur.ROLE_ID, 
			r.role_name,
			ur.ROLE_TYPE, 
			ur.created_by, 
			ur.creation_date, 
			ur.modified_by, 
			ur.modified_date
		FROM 
			t_user_roles ur,t_user u ,t_roles r
		WHERE ur.user_id = u.user_id AND 
			r.role_id = ur.role_id 
			<if test="roleAuthorize.roleAuthorizeId != null and roleAuthorize.roleAuthorizeId != ''">
				and ur.role_id = #{roleAuthorize.roleAuthorizeId}
			</if>
			<if test="roleAuthorize.roleAuthorizeType != null and roleAuthorize.roleAuthorizeType != ''">
				and ur.roleType = #{roleAuthorize.roleAuthorizeType}
			</if>
			<if test="roleAuthorize.userId != null and roleAuthorize.userId != ''">
				and ur.user_id = #{roleAuthorize.userId}
			</if>
	</select>

 

解决方案:

错误的原因在于在Mybatis接口类传入进来的对象不需要xxx对象.xxx属性,如果使用这种就会抛出以下异常,. 直接使用属性名即可。

 

改成以下就没有问题了:

 

<!-- 根据角色ID、角色类型、用户ID查询出角色列表-->
	<select id="getUsersByRoleAuthorize" resultMap="RoleResultMap">
		SELECT 	
			u.USER_ID, 
			u.user_name,
			u.user_status,
			ur.ROLE_ID, 
			r.role_name,
			ur.ROLE_TYPE, 
			ur.created_by, 
			ur.creation_date, 
			ur.modified_by, 
			ur.modified_date
		FROM 
			t_user_roles ur,t_user u ,t_roles r
		WHERE ur.user_id = u.user_id AND 
			r.role_id = ur.role_id 
			<if test="roleAuthorizeId != null and roleAuthorizeId != ''">
				and ur.role_id = #{roleAuthorizeId}
			</if>
			<if test="roleAuthorizeType != null and roleAuthorizeType != ''">
				and ur.roleType = #{roleAuthorizeType}
			</if>
			<if test="userId != null and userId != ''">
				and ur.user_id = #{userId}
			</if>
	</select>
 

 

 

异常信息:

org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.

at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:238)

at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:107)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:61)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:56)

at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:118)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)

at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232)

at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)

at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:236)

... 60 more

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值