2021-08-17 21:54:49 +08:00
|
|
|
|
---
|
2021-08-17 22:51:18 +08:00
|
|
|
|
title: 怎样快速构建项目
|
|
|
|
|
description: 描述怎样快速配置可以运行的空项目
|
2021-08-17 21:54:49 +08:00
|
|
|
|
published: true
|
2021-08-17 22:51:18 +08:00
|
|
|
|
date: 2021-08-17T14:51:16.947Z
|
2021-08-17 21:54:49 +08:00
|
|
|
|
tags: wg-basic
|
|
|
|
|
editor: markdown
|
|
|
|
|
dateCreated: 2021-08-17T13:54:47.580Z
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建项目
|
|
|
|
|
|
|
|
|
|
使用IDEA创建SpringBoot项目
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
| 名称 | 说明 |
|
|
|
|
|
|--|--|
|
|
|
|
|
| Name | 项目名称,推荐使用英文单词组合创建名字,单词之间用英文减号“-”链接 |
|
|
|
|
|
| Languate | 项目语言,这里默认Java |
|
|
|
|
|
| Type | 依赖管理工具,这里默认Maven |
|
|
|
|
|
| Group | 组ID,应为公司域名倒叙写,如com.cn |
|
|
|
|
|
| Artifact | 项目唯一标识,推荐使用英文单词组合创建名字,单词之间用英文减号“-”链接,默认与项目名称一致 |
|
|
|
|
|
| Package name | 启动类所在包 |
|
|
|
|
|
| Project SDK | 这里选择1.8 |
|
|
|
|
|
| Java | java版本,这里与SDK同步,选择8 |
|
|
|
|
|
| Packaging | 打包方式,默认为Jar |
|
|
|
|
|
|
|
|
|
|
注意:这里SpringBoot的版本在 **2.1.2.RELEASE** 版本之上
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# POM依赖
|
|
|
|
|
|
|
|
|
|
properties属性
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<properties>
|
|
|
|
|
<java.version>1.8</java.version>
|
|
|
|
|
<spring-mybatis.version>2.1.4</spring-mybatis.version>
|
|
|
|
|
<mysql.version>8.0.22</mysql.version>
|
|
|
|
|
<druid.version>1.1.9</druid.version>
|
|
|
|
|
</properties>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
dependencies依赖
|
|
|
|
|
|
|
|
|
|
1. SpringBoot项目必须依赖
|
|
|
|
|
```xml
|
|
|
|
|
<dependencies>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
|
|
<artifactId>spring-boot-starter-web</artifactId>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
|
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
|
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>mysql</groupId>
|
|
|
|
|
<artifactId>mysql-connector-java</artifactId>
|
|
|
|
|
<version>${mysql.version}</version>
|
|
|
|
|
<scope>runtime</scope>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
|
|
<artifactId>spring-boot-starter-test</artifactId>
|
|
|
|
|
<scope>test</scope>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>org.mybatis.spring.boot</groupId>
|
|
|
|
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
|
|
|
|
<version>${spring-mybatis.version}</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.alibaba</groupId>
|
|
|
|
|
<artifactId>druid-spring-boot-starter</artifactId>
|
|
|
|
|
<version>${druid.version}</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>junit</groupId>
|
|
|
|
|
<artifactId>junit</artifactId>
|
|
|
|
|
<scope>test</scope>
|
|
|
|
|
</dependency>
|
|
|
|
|
</dependencies>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. wg-basic基础项目所需依赖
|
|
|
|
|
```xml
|
|
|
|
|
<dependencies>
|
2021-08-17 22:01:46 +08:00
|
|
|
|
<!-- 角色模块,该模块包含权限模块、菜单模块、组织机构模块、用户模块、文件模块 -->
|
2021-08-17 21:54:49 +08:00
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>ink.wgink</groupId>
|
|
|
|
|
<artifactId>service-role</artifactId>
|
|
|
|
|
<version>1.0-SNAPSHOT</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
<!-- 登录模块,引入该模块后,访问系统需要登录 -->
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>ink.wgink</groupId>
|
|
|
|
|
<artifactId>login-base</artifactId>
|
|
|
|
|
<version>1.0-SNAPSHOT</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
</dependencies>
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-17 22:29:03 +08:00
|
|
|
|
# 系统文件目录
|
2021-08-17 21:54:49 +08:00
|
|
|
|
|
2021-08-17 22:29:03 +08:00
|
|
|
|
| 目录名称 | 说明 |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
| resources | 资源文件目录,**application.yml** 系统配置文件 |
|
|
|
|
|
| resources/mybatis | 存放 **mybatis-config.xml** 配置文件 |
|
|
|
|
|
| resources/mybatis/mapper | 存放 **mapper** 文件 |
|
|
|
|
|
| resources/static | 静态资源文件目录 |
|
|
|
|
|
| resources/static/assets | 系统所需的CSS、JS等资源文件 |
|
|
|
|
|
| resources/static/error | 错误页面文件夹,**403.hmtl**、**404.html**、**500.html** |
|
|
|
|
|
| resources/static/route | 系统静态页面目录 |
|
|
|
|
|
| resources/templates/ | 模板页面与文件目录 |
|
|
|
|
|
| src/main/java | java源代码目录 |
|
|
|
|
|
| src/main/java/xxx | xxx表示文件所在包,可以有多级 |
|
|
|
|
|
| src/main/java/xxx/controller | controller层代码目录 |
|
|
|
|
|
| src/main/java/xxx/service | service层代码目录 |
|
|
|
|
|
| src/main/java/xxx/dao | dao层代码目录 |
|
|
|
|
|
| src/main/java/xxx/pojo | 实体类存放目录 |
|
|
|
|
|
| src/main/java/xxx/pojo/bos | 业务实体类目录 |
|
|
|
|
|
| src/main/java/xxx/pojo/dtos | 数据传输实体类目录 |
|
|
|
|
|
| src/main/java/xxx/pojo/pos | 数据实体类目录 |
|
|
|
|
|
| src/main/java/xxx/pojo/vos | 视图实体类目录 |
|
|
|
|
|
|
|
|
|
|
# 系统所需文件
|
|
|
|
|
## application.yml
|
2021-08-17 21:54:49 +08:00
|
|
|
|
|
|
|
|
|
```yml
|
2021-08-17 22:01:46 +08:00
|
|
|
|
server:
|
|
|
|
|
port: 8080
|
|
|
|
|
url: http://127.0.0.1:8080/system-name
|
|
|
|
|
system-title: 系统名称
|
|
|
|
|
system-sub-title: 系统子名称
|
|
|
|
|
servlet:
|
|
|
|
|
context-path: /system-name
|
|
|
|
|
|
|
|
|
|
spring:
|
|
|
|
|
login-url: /oauth/login
|
|
|
|
|
login-failure: /oauth/login?error
|
|
|
|
|
login-process: /userlogin
|
|
|
|
|
assets-matchers: /assets/**
|
|
|
|
|
thymeleaf:
|
|
|
|
|
prefix: classpath:/templates/
|
|
|
|
|
suffix: .html
|
|
|
|
|
mode: HTML5
|
|
|
|
|
encoding: UTF-8
|
|
|
|
|
cache: false
|
|
|
|
|
main:
|
|
|
|
|
allow-bean-definition-overriding: true
|
|
|
|
|
servlet:
|
|
|
|
|
multipart:
|
|
|
|
|
max-file-size: 1GB
|
|
|
|
|
max-request-size: 1GB
|
|
|
|
|
datasource:
|
|
|
|
|
druid:
|
|
|
|
|
url: jdbc:mysql://127.0.0.1:3306/db_system?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
|
|
|
|
db-type: mysql
|
|
|
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
|
|
|
username: root
|
|
|
|
|
password: root
|
|
|
|
|
initial-size: 2
|
|
|
|
|
min-idle: 2
|
|
|
|
|
max-active: 5
|
|
|
|
|
max-wait: 60000
|
|
|
|
|
time-between-eviction-runs-millis: 60000
|
|
|
|
|
min-evictable-idle-time-millis: 300000
|
|
|
|
|
validation-query: SELECT 1 FROM DUAL
|
|
|
|
|
test-while-idle: true
|
|
|
|
|
test-on-borrow: false
|
|
|
|
|
test-on-return: false
|
|
|
|
|
pool-prepared-statements: true
|
|
|
|
|
max-pool-prepared-statement-per-connection-size: 10
|
|
|
|
|
filter:
|
|
|
|
|
commons-log:
|
|
|
|
|
connection-logger-name: stat,wall,log4j
|
|
|
|
|
stat:
|
|
|
|
|
log-slow-sql: true
|
|
|
|
|
slow-sql-millis: 2000
|
|
|
|
|
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
|
|
|
|
use-global-data-source-stat: true
|
|
|
|
|
|
|
|
|
|
mybatis:
|
|
|
|
|
config-location: classpath:mybatis/mybatis-config.xml
|
|
|
|
|
mapper-locations: classpath*:mybatis/mapper/**/*.xml
|
|
|
|
|
|
|
|
|
|
swagger:
|
|
|
|
|
base-package-list: ink.wgink,com.cn
|
|
|
|
|
|
|
|
|
|
file:
|
|
|
|
|
# 文件的保存路径,斜杠结尾
|
|
|
|
|
upload-path: /upload/file/path/
|
|
|
|
|
# 图片类型
|
|
|
|
|
image-types: png,jpg,jpeg,gif,blob
|
|
|
|
|
# 视频类型
|
|
|
|
|
video-types: mp4,rmvb
|
|
|
|
|
# 音频类型
|
|
|
|
|
audio-types: mp3,wmv,amr
|
|
|
|
|
# 文件类型
|
|
|
|
|
file-types: doc,docx,xls,xlsx,ppt,pptx,txt,zip,rar,apk,pdf
|
|
|
|
|
# 同时上传最大支持数
|
|
|
|
|
max-file-count: 6
|
|
|
|
|
# 图片输出压缩质量,大于0,默认0.4
|
|
|
|
|
image-output-quality: 0.4
|
|
|
|
|
|
|
|
|
|
logging:
|
|
|
|
|
file:
|
|
|
|
|
name: /log/file/path/logs.log
|
|
|
|
|
level:
|
|
|
|
|
root: error
|
|
|
|
|
org.springframework.boot.autoconfigure.security.servlet: debug
|
|
|
|
|
ink.wgink: debug
|
|
|
|
|
com.cn: debug
|
2021-08-17 21:54:49 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-08-17 22:29:03 +08:00
|
|
|
|
## mybatis-config.xml
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
|
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
|
|
|
|
<configuration>
|
|
|
|
|
<typeAliases>
|
|
|
|
|
<typeAlias type="java.util.Map" alias="map"/>
|
|
|
|
|
<typeAlias type="java.util.List" alias="list"/>
|
|
|
|
|
</typeAliases>
|
|
|
|
|
<plugins>
|
|
|
|
|
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
|
|
|
|
|
</plugins>
|
|
|
|
|
</configuration>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 403.html
|
2021-08-17 21:54:49 +08:00
|
|
|
|
|
2021-08-17 22:29:03 +08:00
|
|
|
|
```html
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<base href="/study/">
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="renderer" content="webkit">
|
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, appversion-scalable=0">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="layui-fluid">
|
|
|
|
|
<div class="layadmin-tips">
|
|
|
|
|
<i class="layui-icon" face></i>
|
|
|
|
|
<div class="layui-text">
|
|
|
|
|
权限不足
|
|
|
|
|
<h1>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">4</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">0</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">3</span>
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 404.hmtl
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<base href="/study/">
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="renderer" content="webkit">
|
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, appversion-scalable=0">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="layui-fluid">
|
|
|
|
|
<div class="layadmin-tips">
|
|
|
|
|
<i class="layui-icon" face></i>
|
|
|
|
|
<div class="layui-text">
|
|
|
|
|
无法访问
|
|
|
|
|
<h1>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">4</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">0</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">4</span>
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 405.html
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<base href="/study/">
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="renderer" content="webkit">
|
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, appversion-scalable=0">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
|
|
|
|
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="layui-fluid">
|
|
|
|
|
<div class="layadmin-tips">
|
|
|
|
|
<i class="layui-icon" face></i>
|
|
|
|
|
<div class="layui-text">
|
|
|
|
|
系统错误
|
|
|
|
|
<h1>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">5</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">0</span>
|
|
|
|
|
<span class="layui-anim layui-anim-loop layui-anim-rotate">0</span>
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
```
|
2021-08-17 21:54:49 +08:00
|
|
|
|
|
2021-08-17 22:32:03 +08:00
|
|
|
|
## 静态资源包
|
|
|
|
|
|
2021-08-17 22:43:16 +08:00
|
|
|
|
> **assets\*.zip** 资源包解压之后,将子目录全部放入 **/resources/static/assets/** 目录即可
|
|
|
|
|
{.is-info}
|
2021-08-17 22:32:03 +08:00
|
|
|
|
|
2021-08-17 22:43:16 +08:00
|
|
|
|
|
|
|
|
|
| 资源名称 | 说明 |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
| [assets1.0.zip](/assets静态资源包/assets1.0.zip) | 默认资源包 |
|
|
|
|
|
|
|
|
|
|
# 启动类
|
|
|
|
|
|
|
|
|
|
**XXX**Application.java,*XXX* 根据实际情况变化
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
|
|
|
|
|
package com.cn.xxx;
|
|
|
|
|
|
|
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
|
|
|
|
|
|
|
@EnableSwagger2
|
2021-08-17 22:45:38 +08:00
|
|
|
|
// Spring 自动扫包根路径,可以配置多个,但第一个必须存在
|
|
|
|
|
@SpringBootApplication(scanBasePackages = {"ink.wgink", "com.cn", "com1.cn"})
|
|
|
|
|
// dao 自动扫描根路径,可以配置多个,但第一个必须存在
|
|
|
|
|
@MapperScan(basePackages = {"ink.wgink.**.dao", "com.cn.**.dao", "com1.cn.**.dao"})
|
2021-08-17 22:43:16 +08:00
|
|
|
|
public class XXXApplication {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
SpringApplication.run(XXXApplication.class, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|