1. 程式人生 > >Mybatis報錯:java.lang.IllegalArgumentException: Result Maps collection does not contain value for java

Mybatis報錯:java.lang.IllegalArgumentException: Result Maps collection does not contain value for java

在練習Shiro的過程中,Mybatis報錯:

十二月 25, 2018 3:53:12 下午 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet [springmvc] in context with path [/shiro] threw exception [Request processing failed; nested exception is org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - 張三, rememberMe=true].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).] with root cause
java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.String
	at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:860)
	at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:612)
	at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344)
	at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:278)
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)
	at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:760)
。。。。。。
以下報錯資訊省略,主要看前幾行錯誤就可以了

後來通過分析,發現之前為Mybatis的多表聯合查詢方式,但後來修改之後,沒有把resultMap改成resultType,導致程式執行出錯;修改之後,再次執行,結果正常:

<select id="selPermissionsByUser" parameterType="user" resultType="java.lang.String">
 		select rp.permission_id from user_role ur, role_permission rp, user
 		where  ur.role_id = rp.role_id
		and user.id = ur.user_id 		
 		and user.name = #{name};
</select>

resultType:一般作為SQL查詢結果的返回值型別,多為基本資料型別。

resultMap:一般多表聯合查詢時,和<resultMap >標籤中的id屬性值對應。