SpringBoot入门小项目springboot+mybatis+mysql+thymeleaf实现数据库操作并展示数据
1. springboot的demo项目快速部署下载
2. MySQL安装下载
此处不做描述
3. 代码
3.1 依赖
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
compile('mysql:mysql-connector-java')
compile 'net.sourceforge.nekohtml:nekohtml:1.9.12'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf:1.5.9.RELEASE'
}
mybatis依赖+mysql数据库连接池
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
compile('mysql:mysql-connector-java')
thymeleaf插件
(nekohtml能够有效的避免html页面中缺少/引起的报错)
compile 'net.sourceforge.nekohtml:nekohtml:1.9.12'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf:1.5.9.RELEASE'
3.2 配置文件
server.port= 8070
#数据库连接(useSSL=true能够有效的避免mysql版本过高引起的报错)
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=true&verifyServerCertificate=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#配置mybatis需要扫描的包
mybatis.typeAliasesPackage=com.example.demo.entity
mybatis.mapperLocations=classpath:mapper/*Mapper.xml
#配置thymeleaf要扫描的html所在的包
spring.thymeleaf.prefix=classpath:/static
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
3.3 项目结构
3.4 代码内容
3.4.1 实体类Person.java
这边省略了set和get(这个是很小的demo 偷懒了)
package com.example.demo.entity;
public