代码生成器:https://gitee.com/renrenio/renren-generator
克隆项目
git clone https://gitee.com/renrenio/renren-generator
删除克隆项目里的.git
目录
导入项目到idea模块
将克隆的项目复制到idea中作为模块运行。
修改配置文件application.yml
,主要是配置数据源
修改配置文件generator.properties
修改controller
模板文件,因为此项目权限验证使用的是springsecurity,而模板文件中使用的是shiro的权限验证,将此注解注释掉。
创建common公共模块,存放公共类
每个模块依赖common模块
common模块结构
pom.xml
文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gulimall</artifactId>
<groupId>com.pumpkin.gulimall</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gulimall-common</artifactId>
<description>每一个微服务公共的依赖,bean,工具类等</description>
<dependencies>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<!-- java发送http请求 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.12</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>javax.servlet</groupId>-->
<!-- <artifactId>servlet-api</artifactId>-->
<!-- <version>2.5</version>-->
<!-- </dependency>-->
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
</dependencies>
</project>
整合mybatis plus
- 导入依赖
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
- 配置
- 配置数据源
- 导入数据库的驱动
- 配置数据源
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
2. 在`application.yml`配置数据源相关信息
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
- 配置mybatis plus
- 在主启动类上加注解
@MapperScan("dao层路径")
- 在主启动类上加注解
@SpringBootApplication
@MapperScan("com.pumpkin.gulimall.ware.dao")
public class GulimallWareApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallWareApplication.class, args);
}
}
2. 配置`application.yml`,告诉mybatis-plus,sql映射文件位置
mybatis-plus:
global-config:
db-config:
id-type: auto # id自增
mapper-locations: classpath*:/mapper/**/*.xml