<resultMap id="BaseResultTreeMap" type="com.shic.edu.model.vo.platform.EduPlatformLearnTypeLearnVo"> <id column="id" property="id"/> <result column="type_name" property="typeName"/> <result column="parent_id" property="parentId"/> <result column="sort" property="sort"/> <result column="help_center_default" property="helpCenterDefault"/> <collection property="platformHelpLearnVos" ofType="com.shic.edu.model.vo.platform.EduPlatformHelpLearnVo" column="type_id"> <id column="learnId" property="learnId"/> <result column="learn_name" property="learnName"/> <result column="type_id" property="typeId"/> <result column="publish_time" property="publishTime"/> <result column="type" property="type"/> <result column="learn_content" property="learnContent"/> </collection> </resultMap> 结果为空
时间: 2023-07-19 12:53:40 浏览: 50
这段代码是一个 MyBatis 的 resultMap,用于将查询结果映射成一个 EduPlatformLearnTypeLearnVo 对象,其中包含一个平台学习类型的信息以及该类型下的学习帮助信息。根据您提供的信息,可能是因为查询结果为空导致没有生成对象。您可以检查一下查询语句或者数据库中是否存在对应的数据。
相关问题
<mapper namespace="com.kangxg.mapper.UserMapper"> <!-- 根据id 查询订单信息 --> <select id="findUserWithOrders" parameterType = "Integer" resultMap="UserWithOrdersResult"> select u.*,o.id as orders_id,o.number from tb_user u,tb_orders o where u.id = o.user_id and u.id = #{id} </select> <resultMap type="com.kangxg.po.User" id="UserWithOrdersResult"> <id property = "id" column = "id"/> <result property = "username" column = "username"/> <result property = "address" column = "address"/> <collection property = "com.kangxg.po.ordersList" ofType = "Orders"> <id property ="id" column ="orders_id"/> <result property ="number" column = "number"/> </collection> </resultMap> </mapper> 对以上代码进行优化改错
根据你提供的代码,我看到了一些问题。下面是对代码进行优化和修正的建议:
1. 首先,你需要将 `resultMap` 的定义放在 `select` 语句之前。
```xml
<mapper namespace="com.kangxg.mapper.UserMapper">
<resultMap type="com.kangxg.po.User" id="UserWithOrdersResult">
<id property="id" column="id"/>
<result property="username" column="username"/>
<result property="address" column="address"/>
<collection property="ordersList" ofType="com.kangxg.po.Orders">
<id property="id" column="orders_id"/>
<result property="number" column="number"/>
</collection>
</resultMap>
<!-- 根据id查询订单信息 -->
<select id="findUserWithOrders" parameterType="Integer" resultMap="UserWithOrdersResult">
SELECT u.*, o.id AS orders_id, o.number
FROM tb_user u, tb_orders o
WHERE u.id = o.user_id
AND u.id = #{id}
</select>
</mapper>
```
2. 注意在 `collection` 元素中,属性名应该是 `ordersList`,而不是 `com.kangxg.po.ordersList`。此外,`ofType` 属性应该指定为 `com.kangxg.po.Orders`,而不是 `Orders`。
3. 确保 `parameterType` 的值与查询语句中的参数类型匹配。
请根据这些建议对你的代码进行修改,并确保其他相关的配置也正确无误。如果还有其他问题,请提供更多的信息。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xie.mapper.StudentInfoMapper"> <resultMap id="studentinfo" type="com.xie.pojo.StudentInfo"> <id column="student_id" property="studentid"/> <result column="student_name" property="studentname"/> <result column="student_tel" property="studenttel"/> <result column="student_pwd" property="studentpwd"/> <result column="student_card" property="studentcard"/> <result column="student_email" property="studentemail"/> <result column="student_ctime" property="studentctime"/> </resultMap> <resultMap id="entryVo" type="com.xie.vo.EntryVo"> <id column="audit.audit_id" property="auditid"/> <result column="exam.exam_name" property="examname"/> <result column="exam.exam_subject" property="examsubject"/> <result column="audit.audit_state" property="auditstate"/> </resultMap> <resultMap id="permitVo" type="com.xie.vo.PermitVo"> <id column="permit.permit_id" property="permitid"/> <result column="permit.permit_number" property="permitnumber"/> <result column="exam.exam_name" property="examname"/> <result column="exam.exam_subject" property="examsubject"/> <result column="exam.exam_stime" property="examstime"/> <result column="exam.exam_etime" property="exametime"/> </resultMap>
这是一个 MyBatis 的 XML 映射文件,用于将 SQL 语句与 Java 接口方法进行映射。该文件定义了多个 resultMap,用于将查询结果映射为 Java 对象。其中 `studentinfo` resultMap 将查询结果映射为 `com.xie.pojo.StudentInfo` 类型的对象,包括学生 ID、姓名、手机号、密码、身份证号、邮箱、创建时间等属性。`entryVo` resultMap 将查询结果映射为 `com.xie.vo.EntryVo` 类型的对象,包括审核 ID、考试名称、考试科目、审核状态等属性。`permitVo` resultMap 将查询结果映射为 `com.xie.vo.PermitVo` 类型的对象,包括许可证 ID、许可证号码、考试名称、考试科目、考试开始时间、考试结束时间等属性。这些 resultMap 的定义将在接下来的 SQL 语句中使用。