1、创建好项目之后在
配置端口号(也可以不用配置,默认端口8080)
#server
server.port=8080server.tomcat.uri-encoding=utf-8
2、配置mysql
#MySQL
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8
spring.datasource.username=*****spring.datasource.password=*****
3、配置jpa以及视图层
#Spring Data JPA
spring.jpa.database=MYSQL
spring.jpa.show-sql=truespring.jpa.hibernate.ddl-auto=update
# Naming strategy
spring.jpa.hibernate.naming-strategy =org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
#视图层控制
spring.mvc.view.prefix=classpath:/templates/spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
4、在pom中加入springboot需要的依赖
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
5.1.39
org.springframework.boot
spring-boot-starter-thymeleaf
1.4.0.RELEASE
org.springframework.boot
spring-boot-starter-data-jpa
1.5.1.RELEASE
com.alibaba
fastjson
1.2.46
整个包结构
Controller
package com.song.configuration.controller;
import com.alibaba.fastjson.JSONObject;
import com.song.configuration.entity.User;
import com.song.configuration.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web