SpringBoot实战项目(一)--构建项目基本框架

后端:SpringBoot + MySQL8.0.15 +Mybatis+Druid

前端:基于layui的轻量级前端后台管理框架

接口文档:Swagger

模板引擎:thymeleaf


  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4     <modelVersion>4.0.0</modelVersion>
  5     <parent>
  6         <groupId>org.springframework.boot</groupId>
  7         <artifactId>spring-boot-starter-parent</artifactId>
  8         <version>2.2.5.RELEASE</version>
  9         <relativePath/> <!-- lookup parent from repository -->
 10     </parent>
 11     <groupId>com.beilin</groupId>
 12     <artifactId>demo</artifactId>
 13     <version>0.0.1-SNAPSHOT</version>
 14     <name>demo</name>
 15     <description>Demo project for Spring Boot</description>
 16 
 17     <properties>
 18         <java.version>1.8</java.version>
 19     </properties>
 20 
 21     <dependencies>
 22         <dependency>
 23             <groupId>org.springframework.boot</groupId>
 24             <artifactId>spring-boot-starter-web</artifactId>
 25         </dependency>
 26         <!--mysql依赖-->
 27         <dependency>
 28             <groupId>mysql</groupId>
 29             <artifactId>mysql-connector-java</artifactId>
 30             <version>8.0.15</version>
 31         </dependency>
 32         <!--mybatis依赖-->
 33         <dependency>
 34             <groupId>org.mybatis.spring.boot</groupId>
 35             <artifactId>mybatis-spring-boot-starter</artifactId>
 36             <version>2.1.0</version>
 37         </dependency>
 38         <dependency>
 39             <groupId>com.github.pagehelper</groupId>
 40             <artifactId>pagehelper</artifactId>
 41             <version>5.1.8</version>
 42         </dependency>
 43 
 44         <!-- 阿里系的Druid依赖包 -->
 45         <dependency>
 46             <groupId>com.alibaba</groupId>
 47             <artifactId>druid-spring-boot-starter</artifactId>
 48             <version>1.1.10</version>
 49         </dependency>
 50         <!-- 引入thymeleaf模板引擎-->
 51         <dependency>
 52             <groupId>org.springframework.boot</groupId>
 53             <artifactId>spring-boot-starter-thymeleaf</artifactId>
 54         </dependency>
 55         <!--Sprinh Security-->
 56 <!--        <dependency>-->
 57 <!--            <groupId>org.springframework.boot</groupId>-->
 58 <!--            <artifactId>spring-boot-starter-security</artifactId>-->
 59 <!--        </dependency>-->
 60         <dependency>
 61             <groupId>io.springfox</groupId>
 62             <artifactId>springfox-swagger2</artifactId>
 63             <version>2.9.2</version>
 64         </dependency>
 65         <dependency>
 66              <groupId>io.springfox</groupId>
 67              <artifactId>springfox-swagger-ui</artifactId>
 68              <version>2.9.2</version>
 69         </dependency>
 70 <!--        &lt;!&ndash;redis&ndash;&gt;-->
 71 <!--        <dependency>-->
 72 <!--            <groupId>org.springframework.boot</groupId>-->
 73 <!--            <artifactId>spring-boot-starter-data-redis</artifactId>-->
 74 <!--        </dependency>-->
 75          <!--devtools热部署-->
 76         <dependency>
 77             <groupId>org.springframework.boot</groupId>
 78             <artifactId>spring-boot-devtools</artifactId>
 79             <optional>true</optional>
 80         </dependency>
 81         <dependency>
 82             <groupId>org.springframework.boot</groupId>
 83             <artifactId>spring-boot-starter-test</artifactId>
 84             <scope>test</scope>
 85 
 86         </dependency>
 87         <dependency>
 88             <groupId>commons-collections</groupId>
 89             <artifactId>commons-collections</artifactId>
 90             <version>3.2.2</version>
 91         </dependency>
 92         <dependency>
 93             <groupId>org.projectlombok</groupId>
 94             <artifactId>lombok</artifactId>
 95             <optional>true</optional>
 96         </dependency>
 97         <dependency>
 98             <groupId>com.alibaba</groupId>
 99             <artifactId>fastjson</artifactId>
100             <version>1.2.60</version>
101         </dependency>
102     </dependencies>
103 
104     <build>
105         <plugins>
106             <plugin>
107                 <groupId>org.springframework.boot</groupId>
108                 <artifactId>spring-boot-maven-plugin</artifactId>
109             </plugin>
110         </plugins>
111         <resources>
112             <resource>
113                 <directory>src/main/java</directory>
114                 <includes>
115                     <include>**/*.xml</include>
116                 </includes>
117                 <filtering>true</filtering>
118             </resource>
119         </resources>
120     </build>
121 
122 </project>
pom.xml
 1 #项目环境设置
 2 spring.profiles.active=dev
 3 #项目编码设置
 4 spring.http.encoding.force=true
 5 spring.http.encoding.charset=UTF-8
 6 spring.http.encoding.enabled=true
 7 server.tomcat.uri-encoding=UTF-8
 8 
 9 api-url=/api
10 
11 #配置mybatis
12 #配置xml映射路径
13 mybatis.mapper-locations=classpath:com.beilin/mapper/**.xml
14 #配置实体类别名
15 mybatis.type-aliases-package=com.beilin.entity
16 #开启驼峰命名法
17 mybatis.configuration.map-underscore-to-camel-case=true
18 
19 #配置Mysql连接
20 spring.datasource.druid.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC
21 spring.datasource.druid.username=root
22 spring.datasource.druid.password=root
23 spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver
application.properties

导入xadmin(百度搜xadmin)

或者: https://pan.baidu.com/s/1Xf2YWfntCv41qrOc1bajHg 提取码: 6app

SpringBoot实战项目(一)--构建项目基本框架

SpringBoot实战项目(一)--构建项目基本框架

 thymeleaf模板 默认路径resources

静态资源--static 目录

SpringBoot实战项目(一)--构建项目基本框架

 页面--templates

SpringBoot实战项目(一)--构建项目基本框架

 抽取公共资源--templates目录新建header.html

SpringBoot实战项目(一)--构建项目基本框架

 页面引用

SpringBoot实战项目(一)--构建项目基本框架

 测试

 1 @Controller
 2 public class LoginController {
 3 
 4     @GetMapping("/index")
 5     public ModelAndView index(ModelAndView model) {
 6         model.setViewName("index");
 7         return model;
 8     }
 9 
10 }

SpringBoot实战项目(一)--构建项目基本框架