闽公网安备 35020302035485号
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line
-- 监控删除操作的触发器
CREATE TRIGGER trg_sys_config_delete
AFTER DELETE ON sys_config
FOR EACH ROW
INSERT INTO sys_config_oper_log (oper_type, oper_time, data_id)
VALUES ('DELETE', NOW(), OLD.id);
-- 监控插入操作的触发器
CREATE TRIGGER trg_sys_config_insert
AFTER INSERT ON sys_config
FOR EACH ROW
INSERT INTO sys_config_oper_log (oper_type, oper_time, data_id)
VALUES ('INSERT', NOW(), NEW.id);
重新执行业务流程后查询sys_config_oper_log,未发现任何DELETE或INSERT记录,排除了“数据动态变更”的可能性,排查陷入僵局。ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line
<logger name="org.mybatis.spring.SqlSessionTemplate" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE_LOG"/>
</logger>
<!-- 打印Mapper接口调用日志 -->
<logger name="com.example.project.mapper.SysConfigMapper" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE_LOG"/>
</logger>
3.2 分析日志内容ounter(lineounter(lineounter(line DEBUG [main] com.example.project.mapper.SysConfigMapper.selectAll:159 - ==> Preparing: SELECT id, type, config_key, config_value FROM sys_config WHERE type = 1 DEBUG [main] com.example.project.mapper.SysConfigMapper.selectAll:159 - ==> Parameters: DEBUG [main] com.example.project.mapper.SysConfigMapper.selectAll:159 - <== Total: 0日志明确显示:SQL中被硬编码添加了WHERE type = 1条件,而数据库中现存数据的type值为2,导致查询结果为空。
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line
<!-- 问题代码:自动生成后被手动添加了WHERE条件 -->
<select id="selectAll" resultMap="BaseResultMap">
select
id, type, config_key, config_value
from
sys_config
where
type = 1 <!-- 多余的硬编码条件 -->
</select>
正常情况下,自动生成工具生成的selectAll方法应无额外条件,代码如下:ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line
<!-- 正确代码:自动生成的默认配置 -->
<select id="selectAll" resultMap="BaseResultMap">
select
id, type, config_key, config_value
from
sys_config
</select>
经沟通确认,此前维护人员为临时满足某需求,直接修改了自动生成的Mapper.xml文件,且未在文档中记录,导致后续迭代中该硬编码条件成为“隐藏坑”。优先怀疑业务逻辑而非框架配置:面对查询空值,先陷入“业务删插数据”的复杂假设,却忽略了“SQL语句与预期不符”这一最直接的可能性。