springboot集成功能:数据库链接(未用数据库连接池)、html页面访问、静态资源存放调用、hibernate Jpa、springboot热部署、Lombok省略getset方法ide安装相关插件、返回给前端统一jackson时间格式化
springboot项目创建步骤:
创建步骤1.png 创建步骤2.png 创建步骤3.png 创建步骤4.png
目录结构:
springboot目录结构详解
<?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.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dist</groupId>
<artifactId>springbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springbootdemo</name>
<description>Demo project for Spring Boot</description>
<!--全局变量-->
<properties>
<java.version>1.8</java.version>
<oracle.version>11.2.0.3</oracle.version>
<lombok.version>1.16.18</lombok.version>
<druid.version>1.0.14</druid.version>
</properties>
<dependencies>
<!--======== SpringBoot的配置start ===========-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot的内置tomcat-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- hibernate jpa-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--简单快速的访问静态资源(图片、html等)-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--开发阶段使用:springboot热启动(热部署):项目有更改,自动编译:需配置idea true生效-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--======= SpringBoot的配置end =========-->
<!--alibaba数据库连接池:1使用德鲁伊连接池,2在yml中配置-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!--oracle数据库驱动-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.version}</version>
</dependency>
<!-- 使用lombok实现JavaBean的get、set、toString、hashCode、equals等方法的自动生成 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--绑定jdk版本和打包时编码格式utf-8-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>${java.version}</target>
<source>${java.version}</source>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!--打包时跳过测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 8089 # tomcat端口号
servlet:
context-path: /springboot # 项目根路径
spring:
datasource:
url: jdbc:oracle:thin:@127.0.0.1:1521:orcl
username: oms
password: pass
driver-class-name: oracle.jdbc.driver.OracleDriver
jpa:
hibernate:
ddl-auto: update
show-sql: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
serialization:
write-dates-as-timestamps: false
thymeleaf:
prefix: classpath:/templates/
jackson解决返回给前端时,时间格式问题
网友评论