We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MyBatis 源码中,根据形参去判断 动态组装的 SQL,被脚本统一成固定 SQL
// 以下代码仅做示例展示 SqlSession sqlSession = MyBatisUtil.getSqlSession(); mapper = sqlSession.getMapper(TaskMapper.class); System.out.println("1-----" + mapper.queryAll(Task.builder().title("任务1").build())); System.out.println("2-----" + mapper.queryAll(Task.builder().createUser("zhangsan1").build())); SqlReplaceConfig.setReplaceSqlBySqlId("com.jd.sql.analysis_samples.mapper.TaskMapper.queryAll" , "select * from task where create_user = ?"); System.out.println("3-----" + mapper.queryAll(Task.builder().title("任务2").build())); System.out.println("4-----" + mapper.queryAll(Task.builder().createUser("zhangsan2").build()));
实际运行结果
Before Replace -> select id, title, content, create_user,create_time, update_time from task WHERE title like ? com.jd.sql.analysis_samples.mapper.TaskMapper.queryAll -> select id, title, content, create_user,create_time, update_time from task WHERE title like '任务1' 1-----[Task(id=1, title=任务1, content=任务内容1, createUser=zhangsan1, createTime=Thu Oct 12 04:10:43 CST 2023, updateTime=Thu Oct 12 04:10:43 CST 2023)] Before Replace -> select id, title, content, create_user,create_time, update_time from task WHERE create_user = ? com.jd.sql.analysis_samples.mapper.TaskMapper.queryAll -> select id, title, content, create_user,create_time, update_time from task WHERE create_user = 'zhangsan1' 2-----[Task(id=1, title=任务1, content=任务内容1, createUser=zhangsan1, createTime=Thu Oct 12 04:10:43 CST 2023, updateTime=Thu Oct 12 04:10:43 CST 2023)] Before Replace -> select id, title, content, create_user,create_time, update_time from task WHERE title like ? INFO [main] - sql analysis - sql replace old:select id, title, content, create_user,create_time, update_time from task WHERE title like ? INFO [main] - sql analysis - sql replace new:select * from task where create_user = ? com.jd.sql.analysis_samples.mapper.TaskMapper.queryAll -> select * from task where create_user = '任务2' 3-----[] <----------- ❌ ❌ ❌ 这个就异常了 Before Replace -> select id, title, content, create_user,create_time, update_time from task WHERE create_user = ? INFO [main] - sql analysis - sql replace old:select id, title, content, create_user,create_time, update_time from task WHERE create_user = ? INFO [main] - sql analysis - sql replace new:select * from task where create_user = ? com.jd.sql.analysis_samples.mapper.TaskMapper.queryAll -> select * from task where create_user = 'zhangsan2' 4-----[Task(id=2, title=任务2, content=任务内容2, createUser=zhangsan2, createTime=Fri Oct 13 05:10:43 CST 2023, updateTime=Fri Oct 13 05:10:43 CST 2023)]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
MyBatis 源码中,根据形参去判断 动态组装的 SQL,被脚本统一成固定 SQL
实际运行结果
The text was updated successfully, but these errors were encountered: