# 基础构建

# Maven添加依赖

中央仓库查询:https://search.maven.org/

阿里仓库查询:https://maven.aliyun.com/mvn/search

<dependency>
  <groupId>com.starmcc</groupId>
  <artifactId>qm-framework</artifactId>
  <version>1.2.1-RELEASE</version>
</dependency>
1
2
3
4
5

注意:框架底层依赖springboot2.1.5以上版本。

已依赖mybatis-spring-boot-starter, spring-boot-starter-web

下面是一套基础的Maven配置

<?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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.starmcc</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1</version>
    <name>demo</name>
    <description>Demo project for Spring Boot and qm-framework</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.starmcc</groupId>
            <artifactId>qm-framework</artifactId>
            <version>1.2.1-RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# 添加配置

springboot中的application.yml添加下列配置。

qmframework:
 # ※※※※※※※※※通讯配置※※※※※※※※※
 transmit: 
   # 请求数据时,最外层的key名(rest风格)
   request-key: 'value'
   # 返回数据时,最外层的key名(rest风格)
   response-key: 'value'
   # 返回数据时,默认message的语言 EN/CN
   response-message-lang: EN
1
2
3
4
5
6
7
8
9

配置数据源

spring:
  datasource:
    druid:
      driver-class-name: 'com.mysql.cj.jdbc.Driver'
      url: 'jdbc:mysql://localhost:3306/test'
      username: 'root'
      password: '123456'
      # 连接池的配置信息
      # 初始化大小,最小,最大
      initial-size: 5
      min-idle: 5
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 300000
      validationQuery: SELECT 1 FROM DUAL
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      # 打开PSCache,并且指定每个连接上PSCache的大小
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filters: stat,wall,slf4j
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connectionProperties: 'stat.mergeSql=true;druid.stat.slowSqlMillis=5000'
      # 配置DruidStatFilter
      web-stat-filter:
        enabled: true
        url-pattern: "/*"
        exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
      # 配置DruidStatViewServlet
      stat-view-servlet:
        url-pattern: "/druid/*"
        # IP白名单(没有配置或者为空,则允许所有访问)
        allow: 127.0.0.1
        # IP黑名单 (存在共同时,deny优先于allow)
        deny:
        # 禁用HTML页面上的“Reset All”功能
        reset-enable: false
        # 登录名
        login-username: admin
        # 登录密码
        login-password: 123456
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

这里以 spring boot + mybatis 的模式为例,设置application.yml

mybatis:
  type-aliases-package: com.starmcc.demo.entity # 指定实体类包路径
  mapper-locations:
    - 'classpath:**/*Mapper.xml' # 该行配置请勿修改
  configuration:
    map-underscore-to-camel-case: true #是否启动数据库下划线自动映射实体
    auto-mapping-behavior: full # resultMap 自动映射级别设置
1
2
3
4
5
6
7

# 进入开发

application启动类配置@MapperScan

@SpringBootApplication
@Import({
        QmFrameworkApplication.class,
        QmExceptionHandler.class,
    	
})
@MapperScan("com.starmcc.demo.dao")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

上方使用 @Import 导入框架配置

QmFrameworkApplication 是框架的主配置类,请必须导入它。

QmExceptionHandler 是全局异常配置类,导入即启用全局异常捕获,并以json的形式返回。建议导入。

其他配置请参考相关功能点说明。


启动项目,数据库配置没有错误的情况下,启动成功!

最近更新: 2020/3/5 上午3:52:00