颓废良久,最近想尝试点没接触过的技术。springboot简化了传统spring的工作量,可自由结合第三方框架。实用性极强。
本工程采用maven工程,springboot、mybatis、mysql、thymeleaf模板。
1、目录结构:
2、pom.xml文件
<?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>
<groupId>com.wlg</groupId>
<artifactId>action</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>action</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3、application.properties文件
# mysql 数据库相关配置
# *********************************************
spring.datasource.url = jdbc:mysql://localhost:3306/wlg
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.tomcat.max-active = 20
spring.datasource.dbcp2.max-idle = 8
spring.datasource.dbcp2.min-idle = 8
spring.datasource.dbcp2.initial-size = 10
#mybatis
#***********************************************
mybatis.mapper-locations = classpath*:com.wlg.action.mapper/*Mapper.xml
mybatis.type-aliases-package = com.wlg.action.dao
#tomcat
#***********************************************
server.servlet.context-path = /wlg
server.port = 8080
spring.mvc.static-path-pattern = /**
spring.resources.static-locations = classpath:/static/
#spring.thymeleaf.prefix= classpath:/templates/
spring.thymeleaf.cache = false
#jsp 模板
#spring.mvc.view.prefix = views/
#spring.mvc.view.suffix = .html
#thymeleaf 模板
spring.thymeleaf.prefix = classpath:/templates/views/
spring.thymeleaf.suffix = .html
#log
#***********************************************
logging.file = /log.log
logging.level.org.org.springframework.web = debug
4、控制台打印效果,图案可配置banner.txt;
5.页面及效果。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p th:text="'hello--------------'+${name}+'!'" >
<a href="www.baidu.com">百度</a>
</body>
</html>
总体来说,还是建议大家使用jsp页面,毕竟传统用起来熟悉。html+thymeleaf页面在不熟悉的情况下不建议使用。