【Java】spring boot +mybatis 整合 association报空指针

<resultMap id="userInfoMap" type="com.pwq.www.myProject.user.model.User">

<id property="id" column="id" />

<result property="username" column="username"/>

<result property="password" column="password" />

<association property="gender">

<id property="id" column="id" />

<result property="userId" column="user_id" />

<result property="gender" column="gender" />

</association>

</resultMap>

<select id="selectUserInfo" resultMap="userInfoMap">

SELECT * FROM t_user u LEFT JOIN t_gender g ON (u.id = g.user_id) WHERE u.id = 1

</select>

【Java】spring boot +mybatis 整合 association报空指针

【Java】spring boot +mybatis 整合 association报空指针

然后我调用了selectUserInfo方法报了空指针

【Java】spring boot +mybatis 整合 association报空指针
实际是有值的

【Java】spring boot +mybatis 整合 association报空指针

不知道哪里错了?

回答

resultMap配置不正确,需要增加关联的gender的类型javaType="com.pwq.www.myProject.user.model.Gender"

<resultMap id="userInfoMap" type="com.pwq.www.myProject.user.model.User">

<id property="id" column="id" />

<result property="username" column="username"/>

<result property="password" column="password" />

<association property="gender" javaType="com.pwq.www.myProject.user.model.Gender">

<id property="id" column="id" />

<result property="userId" column="user_id" />

<result property="gender" column="gender" />

</association>

</resultMap>

com.pwq.www.myProject.user.model.Gender 这个是猜的包名,需要再确认下是否是这个。

以上是 【Java】spring boot +mybatis 整合 association报空指针 的全部内容, 来源链接: utcz.com/a/90419.html

回到顶部