现在学系mybatis遇到了一些问题,希望大家帮忙看看问题的所在
现在有两个类管理者类(Manager)和部门类(department)Manage中有个字段是deptId代表所在的部门
现在问题来了,这个deptId定义的时候是不是也和Hibernate一样定义成Department deptId;呢?还是直接用Integer deptId 我用的是后面的 然后插入的时候前台有个下拉菜单选择Department 然后插入 没有问题 问题是读取列表的时候我用的是这样的代码
<resultMap type="Manager" id="managerMap">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="pass" property="pass" />
<result column="status" property="status" />
<association property="deptId" select="department.selectDeptById" column="deptId" resultMap="departmentMap" javaType="Department"/>
</resultMap>
但是提示我
Could not set property 'deptId' of 'me.luger.sys.manager.model.Manager@2898b13b' with value 'me.luger.sys.department.model.Department@409bad4f'
怎么会出现这个问题呢?希望大家帮帮忙。或者谁有demo发给我一份也行 谢谢
现在有两个类管理者类(Manager)和部门类(department)Manage中有个字段是deptId代表所在的部门
现在问题来了,这个deptId定义的时候是不是也和Hibernate一样定义成Department deptId;呢?还是直接用Integer deptId 我用的是后面的 然后插入的时候前台有个下拉菜单选择Department 然后插入 没有问题 问题是读取列表的时候我用的是这样的代码
<resultMap type="Manager" id="managerMap">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="pass" property="pass" />
<result column="status" property="status" />
<association property="deptId" select="department.selectDeptById" column="deptId" resultMap="departmentMap" javaType="Department"/>
</resultMap>
但是提示我
Could not set property 'deptId' of 'me.luger.sys.manager.model.Manager@2898b13b' with value 'me.luger.sys.department.model.Department@409bad4f'
怎么会出现这个问题呢?希望大家帮帮忙。或者谁有demo发给我一份也行 谢谢
<result column="deptId" property="deptId" />
去掉resultMap和javaType指定,因为你在department.selectDeptById语句中已经指定了返回类型,如果selectDeptById名称在所有的map(不仅仅指在department的map文件中)文件中是唯一的话,select不需要指定department限定,如果不唯一,那么你需要指定整个包名,比如com.myapp.mybatis.department.selectDeptById,还有你的manager表的查询结果中应该有一个deptId的列(column="deptId"),还有你的Manager类应该有一个deptId的属性(property="deptId"),有setDeptId()方法