写在前面:工作良久,发现公司没有erp的确是一个难以让人适从的问题,所以突然想到自己写一个试一试,也希望,我写的东西能有人喜欢和尝试。
注:
1. 本人非技术大牛,写的东西,也只是简简单单,望各位看得舒服即可。
2. 每篇文章都有它的局限性,若有失效、环境不同等问题,还请各位自行找寻解决办法,也不失为一场乐趣
- 开发软件:IntelliJ IDEA 2020.3.4 x64
- Java环境:JDK1.8
填写对应的包名、简介,也可默认(此处已填写)
选择 springboot 版本,以及简单的依赖
创建成功后,pom.xml 如下,此处建议大家,自行分类并添加注释(此为个人已添加注释)
4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.8 com.hd erp 1.0.0 war erp This is the personal erp 1.8 org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true org.springframework.boot spring-boot-starter-tomcat provided org.springframework.boot spring-boot-starter-test test mysql mysql-connector-java runtime org.springframework.boot spring-boot-maven-plugin
添加 mybatis-plus、jackson、swagger2 的 pom.xml 依赖
com.baomidou
mybatis-plus-boot-starter
3.0.6
com.baomidou
mybatis-plus-generator
3.2.0
org.springframework.boot
spring-boot-starter-json
io.springfox
springfox-swagger-ui
2.8.0
io.springfox
springfox-swagger2
2.8.0
将 application.properties 更名为 application.yml
在 application.yml 下,添加如下配置
注:url 中的数据库请自行创建,本人命名为:erp
server:
port: 8000
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/erp?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
删除 ServletInitializer.class,添加 config、controller 包,在 config 包下添加 swagger2 配置类 Swagger2Configuration.class
Swagger2Configuration.class 代码如下
注:controller 包路径不要写错
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
@Bean
public Docket createRestApi() {
return new Docket(documentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.hd.erp.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("erp")
.description("erp")
.version("1.0.0")
.termsOfServiceUrl("http://127.0.0.1:8000/")
.build();
}
}
三、测试启动
使用 IDEA 启动,访问地址:http://127.0.0.1:8000/swagger-ui.html,成功访问后如下



