同步操作将从 徐少/qianxunclub-starter-parent 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
SpringBoot咱们开发一般pom.xml
是都集成spring-boot-starter-parent
的,这里为什么要自定义一个starter-parent呢,主要以下几个理由:
其实好处挺多的,谁用谁知道。
qianxunclub-starter-parent
里面已经开发好的几个插件,需要依据公司真实环境修改配置
源码地址:
git clone https://gitee.com/qianxunclub/qianxunclub-starter-parent.git
因为qianxunclub-starter-parent
依赖了另一个framework-common
工具包,所以要下载该包源码并且编译:
git clone https://gitee.com/qianxunclub/framework-common.git
cd framework-common
mvn clean install
本starter已包含一下功能:
POM需要依赖父级qianxunclub-starter-parent
:
<parent>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
继承该依赖,无需再引用spring-boot-starter-parent
,本项目已经继承的spring-boot-starter-parent
版本为1.5.9.RELEASE
。
qianxunclub-demo
├── pom.xml
├── qianxunclub-demo.iml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── qianxunclub
│ │ ├── Application.java
│ │ └── demo
│ │ └── web
│ └── resources
│ └── application.yml
└── test
└── java
app:
group: group
name: demo
descriptions: 项目描述
author: 千寻啊千寻
email: 960339491@qq.com
spring:
profiles:
include:
- web
- swagger
- logging
- mysql
<!-- 日志配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-logging</artifactId>
</dependency>
profiles需要引入配置:
spring:
profiles:
include:
- logging
自定义配置:
logging:
level:
com.qianxunclub: debug
以下为缺省配置:
logging:
level:
org.springframework: info
com.qianxunclub: info
pattern:
console: "%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{64}) - %msg%n"
file: /logs/${app.group:}/${app.name:${spring.application.name:application}}/${spring.application.name:application}.log
** 日志默认存放目录:/logs/项目分组/项目名称/日志文件 如果没有项目分组:/logs/项目名称/日志文件 **
只需要在类上面添加@Slf4j
注解,即可使用log
对象打印日志
@Slf4j
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
log.info("日志信息");
}
}
<!-- 自动生成接口文档 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-swagger</artifactId>
</dependency>
swagger默认是不启用的,必须添加一下配置,才可以开启配置
app:
swagger: true
spring:
profiles:
include:
- swagger
@EnableSBCSwagger
注解,开启接口@EnableSBCSwagger
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
启动项目成功后,访问API接口地址,例如:http://localhost:8080/swagger-ui.html。
<!-- MYSQL配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-mysql</artifactId>
</dependency>
引入mysql配置:
spring:
profiles:
include:
- mysql
添加数据源信息:
app:
group: group
name: oneway
description: demo
author: 千寻啊千寻
email: 960339491@qq.com
datasource:
host: xxx.xxx.xxx.xxx
username: root
password: xxx
druid:
public-key: xxx
端口默认为:3306
数据库密码加密:
java -cp druid-1.1.6.jar com.alibaba.druid.filter.config.ConfigTools your_password
以上配置完成后即可使用mysql以及MybatisPlus,该starter已封装部分常用数据库操作,方法如下:
MybatisPlus使用说明:http://mp.baomidou.com/#/?id=%e7%ae%80%e4%bb%8b
1、Entity规范
数据库对应的Entity需要继承BaseEntity
,如下:
@Data
@TableName("t_app")
public class AppEntity extends BaseEntity {
}
2、Param规范
Param为入参查询常用发放,Param需要继承BaseParam
,如下:
@Data
public class AppParam extends BaseParam {
}
3、Mapper规范
需要添加@Mapper
注解,继承BaseMapper
,并且要指定Entity泛型,如下:
@Mapper
public interface AppMapper extends BaseMapper<AppEntity> {
}
4、Dao规范
需要继承BaseDao
,并且指定泛型,如下:
@Component
public class AppDao extends BaseDao<AppMapper,AppEntity,AppParam> {
}
5、mapper.xml规范
默认可以不添加mapper.xml,如果遇到特定的SQL,可在resources
资源目录添加mapper文件夹,并添加对应的XML即可
<!-- MYSQL配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-redis</artifactId>
</dependency>
引入mysql配置:
spring:
profiles:
include:
- redis
添加redis配置信息:
spring:
redis:
host: 120.25.173.32
password: 123456
端口默认为:6379
下面为缺省配置:
spring:
redis:
database: 0
host: localhost
port: 6379
password:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池中的最大空闲连接
max-idle: 8
# 连接池中的最小空闲连接
min-idle: 0
# 连接超时时间(毫秒)
timeout: 0
在类中可直接注入RedisTemplate
或StringRedisTemplate
即可使用,例如:
@Slf4j
@RestController
@RequestMapping(value = "/redis")
@AllArgsConstructor
@Api(description = "redis")
public class RedisController {
private RedisTemplate redisTemplate;
private StringRedisTemplate stringRedisTemplate;
@ApiOperation("add")
@ResponseBody
@RequestMapping(value="add",method = RequestMethod.GET)
public void add() {
ValueOperations<String, String> operations=redisTemplate.opsForValue();
operations.set("ValueOperations","1");
log.info(operations.get("ValueOperations"));
stringRedisTemplate.opsForValue().set("aaa", "111");
log.info(stringRedisTemplate.opsForValue().get("aaa"));
}
}
<!-- 支持跨域请求 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-web</artifactId>
</dependency>
profiles需要引入配置:
spring:
profiles:
include:
- web
pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<!-- 自动生成接口文档 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-swagger</artifactId>
</dependency>
<!-- web配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-web</artifactId>
</dependency>
<!-- 日志配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-logging</artifactId>
</dependency>
<!-- MYSQL配置信息 -->
<dependency>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-starter-mysql</artifactId>
</dependency>
</dependencies>
application.yml:
app:
group: group
name: demo
description: demo服务
author: 千寻啊千寻
email: 960339491@qq.com
swagger: true
datasource:
host: xxx.xxx.xxx.xxx
username: root
password: xxx
druid:
public-key: xxx
spring:
profiles:
include:
- web
- swagger
- logging
- mysql
完!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。