踩坑-Mybatis的空格问题

这是一些定义:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

<resultMap id="CourseInfoResultMap" type="com.kedacom.edu.component.course.he.persistence.domain.third.CourseInfo">
<result column="cosc_code " property="scheduleCode"/>
<result column="tecl_code" property="teachingClassCode"/>
<result column="cosc_kszc" property="weekStart"/>
<result column="cosc_jszc" property="weekEnd"/>
<result column="cosc_week" property="weekday"/>
<result column="cosc_jc" property="classHourTime"/>
<result column="cosc_dszdm" property="weekType"/>
<result column="orga_code" property="organizationCode"/>
<result column="subj_code" property="subjectCode"/>
<result column="user_code" property="teacherUserCode"/>
<result column="clro_code" property="classroomCode"/>
</resultMap>

<select id="getCourseInfos" resultMap="CourseInfoResultMap">
SELECT * FROM (
SELECT row_.*, ROWNUM rownum_
FROM (
SELECT DISTINCT cosc_code, tecl_code, cosc_kszc, cosc_jszc, cosc_week, cosc_jc, cosc_dszdm,
orga_code, subj_code, user_code, clro_code
FROM USR_DATA.V_TO_ECVS_T_COURSE_SCHEDULE
) row_
WHERE ROWNUM &lt;= #{pageNum} * #{pageSize}
) paginated_row_
WHERE rownum_ &gt; (#{pageNum} - 1) * #{pageSize}
</select>

是不是没看出来有什么问题?

1
<result column="cosc_code " property="scheduleCode"/>

对,就是这里,cosc_code后面多敲了一个空格,导致获取数据的时候丢失了:

image-20240827161146722

最倒霉的是,这bug完全不能从日志中de出来:

1
2
3
4
5
6
7
2024-08-27 16:05:59.847 [Thread-8] DEBUG com.baomidou.dynamic.datasource.DynamicRoutingDataSource:117 - dynamic-datasource switch to the datasource named [slave]
2024-08-27 16:05:59.847 [Thread-8] DEBUG org.mybatis.spring.transaction.SpringManagedTransaction:49 - JDBC Connection [HikariProxyConnection@5208479 wrapping oracle.jdbc.driver.T4CConnection@1ebd114] will not be managed by Spring
2024-08-27 16:05:59.847 [Thread-8] DEBUG com.kedacom.edu.component.course.he.dao.SchoolCourseMapper.getCourseInfos:137 - ==> Preparing: SELECT * FROM ( SELECT row_.*, ROWNUM rownum_ FROM ( SELECT DISTINCT cosc_code, tecl_code, cosc_kszc, cosc_jszc, cosc_week, cosc_jc, cosc_dszdm, orga_code, subj_code, user_code, clro_code FROM USR_DATA.V_TO_ECVS_T_COURSE_SCHEDULE ) row_ WHERE ROWNUM <= ? * ? ) paginated_row_ WHERE rownum_ > (? - 1) * ?
2024-08-27 16:05:59.849 [Thread-8] DEBUG com.kedacom.edu.component.course.he.dao.SchoolCourseMapper.getCourseInfos:137 - ==> Parameters: 16(Integer), 1000(Integer), 16(Integer), 1000(Integer)
2024-08-27 16:06:05.545 [Thread-8] DEBUG com.kedacom.edu.component.course.he.dao.SchoolCourseMapper.getCourseInfos:137 - <== Total: 527
2024-08-27 16:06:05.546 [Thread-8] DEBUG org.mybatis.spring.SqlSessionUtils:49 - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@12128cd]
2024-08-27 16:06:05.546 [Thread-8] INFO com.kedacom.edu.component.course.he.service.impl.CourseScheduleServiceImpl:58 - 同步第16页527条排课信息

好吧,还是自己太粗心。。。