01.基于Irises的springboot项目框架(简版)
作者:互联网
01.基于Irises的springboot项目框架(简版)
介绍
基于Irises搭建的springboot单体应用框架(简版),支持Mybatis-plus、sql分析与打印、swagger、kknife4j、查询条件自动解析与绑定(单表可随意查询无需编码)。
案例(简单)
创建一个单体springboot项目
1. 创建springboot项目,修改pom.xml
目录结构
使用irises-parent替换spring-boot-starter-parent
<!-- <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!– lookup parent from repository –>
</parent>-->
<!-- 引入Irises父级pom,替代spring-boot-starter-parent -->
<parent>
<groupId>com.irises</groupId>
<artifactId>irises-parent</artifactId>
<version>2.2.1</version>
</parent>
根据自身项目所需引入需要的模块依赖(完整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 https://maven.apache.org/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.4.4</version>
<relativePath/> <!– lookup parent from repository –>
</parent>-->
<!-- 引入Irises父级pom,替代spring-boot-starter-parent -->
<parent>
<groupId>com.irises</groupId>
<artifactId>irises-parent</artifactId>
<version>2.2.1</version>
</parent>
<groupId>com.irises.example</groupId>
<artifactId>bootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bootdemo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.irises</groupId>
<artifactId>irises-commons</artifactId>
</dependency>
<dependency>
<groupId>com.irises</groupId>
<artifactId>irises-web</artifactId>
</dependency>
<dependency>
<groupId>com.irises</groupId>
<artifactId>irises-mybatisplus</artifactId>
</dependency>
<dependency>
<groupId>com.irises</groupId>
<artifactId>irises-mybatisplus-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3. 配置文件
application.properties
# 项目配置
spring.application.name=irises-demo
server.port=8889
###### 数据源配置(比Druid好)
spring.datasource.hikari.minimum-idle=1
spring.datasource.hikari.maximum-pool-size=2
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.max-lifetime=600000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
##### mybatis-plus 配置
#MyBatis Mapper 文件所在路径
mybatis-plus.mapper-locations=classpath*:com/kl/ark/**/mapper/*Mapper.xml
#MyBaits 实体所在包
mybatis-plus.type-aliases-package=com.irises.example.**.entity
#不试用驼峰转换,经过多次项目实践,最终决定数据库字段试用驼峰
mybatis-plus.configuration.map-underscore-to-camel-case=false
# 数据库连接配置
#spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://192.168.0.49:3306/irises_demo?useUnicode=true&characterEncoding=UTF-8&useSSL=true&verifyServerCertificate=false&serverTimezone=Hongkong
#以下两项配置是SQL语句分析打印插件,生产勿用
spring.datasource.driverClassName=com.p6spy.engine.spy.P6SpyDriver
spring.datasource.url=jdbc:p6spy:mysql://192.168.0.49:3306/irises_demo?useUnicode=true&characterEncoding=UTF-8&useSSL=true&verifyServerCertificate=false&serverTimezone=Hongkong
spring.datasource.username=root
spring.datasource.password=rootdb
#swagger2配置
swagger.enabled=true
swagger.title=Irises接口文档
swagger.description=Demo测试接口文档
swagger.termsOfServiceUrl=http://127.0.0.1/
swagger.version=1.0
swagger.groupName=Demo
# 多个路径用逗号隔开
swagger.scanPackages=com.irises.example.bootdemo.controller
#knife4j配置(Swagger的界面)
knife4j.enable=true
knife4j.cors=true
knife4j.setting.enableFooter=false
knife4j.setting.enableFooterCustom=true
knife4j.setting.footerCustomContent=江湖没什么好的,也就酒还行
knife4j.setting.enableDebug=true
#日志配置
logging.irises.file.path=/var/log/irises/example/
logging.irises.level=info
#其它配置
spring.jackson.time-zone=GMT+8
#设置spring-boot 编码格式
banner.charset=UTF-8
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 自定义配置 -->
<springProperty scope="context" name="APP_NAME" source="spring.application.name" />
<springProperty scope="context" name="FILE_PATH" source="logging.irises.file.path" />
<springProperty scope="context" name="LEVEL" source="logging.irises.level" />GeneratorApplication
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${FILE_PATH}/${APP_NAME}" />
<!-- 日志输出格式 -->
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID:-} [%thread] %logger:%L %msg%n" />
<!-- 彩色日志格式 highlight white green cyan blue red yellow black magenta gray boldBlue bold*-->
<property name="CONSOLE_LOG_PATTERN" value="%green(%d{yyyy-MM-dd HH:mm:ss.SSS}) %highlight(%-5level) %boldCyan(${PID:-} [%thread] %logger:%L) %gray(%msg%n)" />
<!-- 控制台输出 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--设置输出格式-->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<!--设置编码-->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--日志名,指定最新的文件名,其他文件名使用FileNamePattern -->
<File>${LOG_HOME}/${APP_NAME}.log</File>
<!--文件滚动模式-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名,可设置文件类型为gz,开启文件压缩-->
<FileNamePattern>${LOG_HOME}/${APP_NAME}.%d{yyyy-MM-dd}.%i.log.gz</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--按大小分割同一天的-->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!--输出格式-->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
<!--设置编码-->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 日志输出级别 -->
<logger name="com.irises.example" level="${LEVEL}" />
<root level="${LEVEL}">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ROLLING_FILE" />
</root>
</configuration>
spy.properties
# SQl语句分析插件配置
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
#日志输出到控制台
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
# 使用日志系统记录 sql
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 设置 p6spy driver 代理
deregisterdrivers=true
# 取消JDBC URL前缀
useprefix=true
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset
# 日期格式
dateformat=yyyy-MM-dd HH:mm:ss
# 实际驱动可多个
#driverlist=org.h2.Driver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 2 秒
outagedetectioninterval=2
4. 配置类
WebConfig.java
package com.irises.example.bootdemo.config;
import com.irises.framework.web.MybatisPlusWebConfig;
import com.irises.framework.web.configuration.IrisesSwaggerConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
/**
* <p>
* 描述:
* </p>
*
* @author 田轩
* @since 2021/1/11
*/
@Configuration
@Import(IrisesSwaggerConfig.class)
public class WebConfig extends MybatisPlusWebConfig {
}
MybatisPlusConfig.java
package com.irises.example.bootdemo.config;
import com.irises.framework.mybatisplus.configuration.IrisesMybatisPlusConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(IrisesMybatisPlusConfig.class)
@MapperScan("com.irises.example.**.mapper")
public class MybatisPlusConfig {
}
5. 建表
DROP TABLE IF EXISTS `wife`;
CREATE TABLE `wife` (
`id` bigint(0) NOT NULL,
`name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
`createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`modifiedTime` datetime(0) NULL DEFAULT NULL COMMENT '最后修改时间',
`creator` bigint(0) NULL DEFAULT NULL COMMENT '创建人ID',
`modifier` bigint(0) NULL DEFAULT NULL COMMENT '修改人',
`deleted` bit(1) NULL DEFAULT NULL COMMENT '删除标记',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
- 生成代码
运行IrisesGenerator.java生成代码
7.启动项目
8.调试接口
在线文档地址:http://localhost:8889/doc.html
调试-添加wife
调试-查询wife
END
相关教程
- 创建springboot单体项目(完整版)
文档努力制作中 - 创建基于springcloud alibaba的项目(完整版)
文档努力制作中
标签:01,springboot,spring,简版,irises,datasource,org,NULL,com 来源: https://blog.csdn.net/cruel_xuan/article/details/115719878