1:无论使用mybatis-plus还是mybatis,只要在springboot的配置文件----appcation.yml中添加:就可以答应sql
logging:
level:
org.jeecg.modules.hdx.mapper: debug
org.jeecg.modules.hdx.mapper为@mapper注解下面的类,或者继承BaseMapper,或者@MapperScan扫描包的类
2:如果使用的是springboot+mybatis-plus的话
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
#主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
id-type: 4
# 默认数据库表下划线命名
table-underline: true
configuration:
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2-1:在pom文件引入依赖文章来源:https://www.toymoban.com/news/detail-649314.html
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
3:如果使用的是springboot+mybatis的话(包含分页)
#数据库的配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
username: root
password: root
#mybatis的配置
mybatis:
configuration:
# sql日志显示,这里使用标准显示
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 数据库中如果有类似 如 user_name 等命名,会将 _后的字母大写,这里是为了和实体类对应
map-underscore-to-camel-case: true
# 配置mapper文件的路径
mapper-locations: classpath:org/jeecg/modules/hdx.mapper/*/mapper/*.xml
#pageHelper配置分页(官网推荐配置)
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
3-1:pom配置(包含分页)文章来源地址https://www.toymoban.com/news/detail-649314.html
<!--web,servlet引入-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mybatis依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--快速操作实体类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--单元测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!—pagehelper mybatis的分页插件依赖-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
到了这里,关于Mybatis 开启控制台打印sql语句的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!