mybatis一对多关联查询问题

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'roles' in 'class com.jsp.system.user.bo.User'
at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380)
at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.instantiateCollectionPropertyIfAppropriate(DefaultResultSetHandler.java:451)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:800)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:758)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:724)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:267)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:239)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:153)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

user.xml配置






<!-- 一对多的关系 -->
<!-- property: 指的是集合属性的值, ofType:指的是集合中元素的类型 -->
    <collection property="roles" javaType="list" ofType="Role">
        <id property="role_id" column="role_id"/>
        <result property="role_name" column="role_name"/>
        <result property="role_code" column="role_code"/>
    </collection>
</resultMap>
<!-- 按照用户ID查找角色信息 -->
<select id="selectUserRole"  parameterType="String"  resultMap="UserMap">
    select u.userName,r.role_name,r.role_name from s_user u,s_role r, s_relate g 
    where u.user_id=g.user_id and r.role_id=g.role_id and u.user_id=#{user_id}

</select>

报错了,找了半天不知道什么原因. 麻烦大神帮看下,或留个联系方式.

1个回答

mybatis 提供了高级的关联查询功能,一对多,多对多,多对一......
答案就在这里:mybatis关联查询问题(一对多、多对一)
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐