springboot入门级学习

颓废良久,最近想尝试点没接触过的技术。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页面在不熟悉的情况下不建议使用。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java旅途

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值