SpringBoot学习-mybaties SQL打印

没啥可说的,配置文件中加上配置信息就可以了

#日志打印
logging.level.org.springframework=WARN
logging.level.com.example.demo.mapper=DEBUG
logging.file=logs/spring-boot-logging.log

第二行配置的Dao层目录路径,后面是日志级别


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot项目中,如果需要在运行Mybatis-plus的SQL语句之前先运行其他SQL语句的触发器,可以通过在配置文件中配置SqlSessionFactoryBean来实现,具体步骤如下: 1. 创建一个类,实现ApplicationRunner接口,重写run方法,在该方法中执行需要先运行的SQL语句。 ```java @Component public class SqlTriggerRunner implements ApplicationRunner { @Autowired private SqlSessionFactory sqlSessionFactory; @Override public void run(ApplicationArguments args) throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); try { sqlSession.update("update table1 set column1=value1 where id=1"); sqlSession.flushStatements(); sqlSession.commit(); } catch (Exception e) { sqlSession.rollback(); throw e; } finally { sqlSession.close(); } } } ``` 2. 在配置文件中配置SqlSessionFactoryBean,指定上面创建的SqlTriggerRunner类,并设置其执行顺序: ```yaml mybatis-plus: mapper-locations: classpath*:mapper/*.xml configuration: map-underscore-to-camel-case: true spring: datasource: url: jdbc:mysql://localhost:3306/test username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver sqlSessionFactory: typeAliasesPackage: com.example.demo.entity mapperLocations: classpath*:mapper/*.xml configuration: map-underscore-to-camel-case: true default-executor-type: BATCH log-impl: org.apache.ibatis.logging.stdout.StdOutImpl before-init-script: classpath:/init.sql # 指定SqlTriggerRunner执行顺序为最高,先执行 initializers: - order: 0 object: com.example.demo.SqlTriggerRunner ``` 在上面的配置文件中,我们指定了SqlTriggerRunner类,并设置其执行顺序为最高,即在所有初始化器中最先执行。这样,当项目启动时,就会先执行SqlTriggerRunner中的SQL语句,然后再执行其他的Mybatis-plus SQL语句。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值