这篇文章将为大家详细讲解有关springboot2 多模块项目中mybatis如何使用,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
可以参考文章创建多模块项目 Go!!!
项目分3个子模块分别是,父级megatron
megatron-api
项目启动类
package com.megatron.module;
import com.megatron.utils.IPUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.megatron.module.dal.mapper") //扫描指定包中的接口
public class MegatronLogApiApplication {
public static Logger logger = LoggerFactory.getLogger(MegatronLogApiApplication.class);
public static void main(String[] args) {
System.setProperty("local-ip", IPUtils.getLocalIp());
SpringApplication.run(MegatronLogApiApplication.class, args);
}
}
application.yml
spring:
datasource:
name: mysql
type: com.alibaba.druid.pool.DruidDataSource
druid:
filter: stat
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/megatron?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
username: root
password:
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 'x'
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
logging:
config: classpath:log4j2-test.yml
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.megatron.module.dal.entity
megatron-impl
mybatis需要用到的pom
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
红框内容是通过mybatis插件生成代码参考插件Go!!!
最后可以看到结果可以正常输出
关于springboot2 多模块项目中mybatis如何使用就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/871354/blog/3097828