基于SpringBoot搭建RestAPI接⼝服务(基于IDEA)1. 项⽬构建
1. IDEA内置了SpringBoot启动
2. 填写项⽬相关信息
3. 根据项⽬需要选择所需依赖,这⾥搭建RestAPI服务
2. 项⽬配置参考
项⽬配置可以配置多个application,开发,测试,⽣产,通过配置spring.profiles.active=dev启⽤不同的配置⽂件1. application.properties
springBoot配置⽂件 (可以按照项⽬需求,把各个环境不变的配置配置在这⾥)
# 配置启动环境加载不同的配置⽂件
spring.profiles.active=dev
# Redis服务器地址
# Redis服务器连接端⼝
# Redis服务器连接密码(默认为空)
# 连接池最⼤连接数(使⽤负值表⽰没有限制)
# 连接池最⼤阻塞等待时间(使⽤负值表⽰没有限制)
# 连接池中的最⼤空闲连接
# 连接池中的最⼩空闲连接
# 连接超时时间(毫秒)
#数据库
pe = com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name = sql.jdbc.Driver
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
# 注意注意
mybatis.mapper-locations= classpath:club/lovewangxi/dal/dao/*.pe-aliases-package=club.ity
# 驼峰命名规范如:数据库字段是 order_id 那么实体字段就要写成 figuration.map-underscore-to-camel-case=true
# = WARN
#springframework.web = DEBUG
##⽐如 mybatis sql⽇志
#batis = INFO
#logging.level.club.lovewangxi.dal = DEBUG
2. application-dev.properties
开发环境
#开发环境
t-path=/payroll
server.port=8081
#JDBC 连接
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
# Redis数据库索引(默认为0)
## ⽇志
logging.level.* = DEBUG
#sole= %d - %msg%n
logging.path=D:/logs/payroll/
logging.file=D:/logs/payroll/logs.log
Maven依赖参考
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.
xsd"> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>club.lovewangxi</groupId>
<artifactId>payroll</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>payroll</name>
<description>Payroll management system</description>
<properties>
<java.version>1.8</java.version>
<druid.version>1.0.29</druid.version>
<fastjson.version>1.2.51</fastjson.version>
<common.version>3.8.1</common.version>
<beanutils.version>1.9.3</beanutils.version>
<lombok.version>1.16.22</lombok.version>
<pagehelper.version>5.0.3</pagehelper.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
idea debug<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--数据库连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.apachemons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${common.version}</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${beanutils.version}</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
</dependencies>
<build>
<!--resources配置解决mybatis 的mapperXml配置在java路径不被扫描的问题 --> <resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
项⽬结构参考
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论