Springboot Integration Hibernate copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced.
Directory (?) [+] Add Springboot Dependency
Using idea to create a MAVEN project, you can refer to the following blog for the creation process:
http://blog.csdn.net/supervictim/article/details/53490046
After you create the MAVEN project, add Springboot dependencies, and the Pom.xml file is as follows:
<dependencyManagement> <dependencies> <dependency> <!--Import dependency Managemen T from Spring Boot--<groupId>org.springframework.boot</groupId> <artifactid>spring -boot-dependencies</artifactid> <version>1.3.5.RELEASE</version> <type>pom</typ e> <scope>import</scope> </dependency> </dependencies> </dependencymanag ement> <dependencies> <dependency> <groupId>junit</groupId> <ARTIFACTID&G t;junit</artifactid> <version>3.8.1</version> <scope>test</scope> </depen Dency> <!--springboot dependent-<dependency> <GROUPID>ORG.SPRINGFRAMEWORK.BOOT</GROUPID&G
T <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <grou Pid>org.spriNgframework.boot</groupid> <artifactId>spring-boot-devtools</artifactId> <optional>tru e</optional> </dependency> <dependency> <groupid>org.springframework.boot</groupi d> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies
> <build> <finalName>hibernateSpringDemo</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-maven-plugin</ar tifactid> <configuration> <fork>true</fork> </configuration> &L T;/plugin> </plugins> </build>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3 9 40 41 42 43 44 45 46 47 48 49
SPRINGMVC Accessing Instances
Add the Springboot dependency above, you can use SPRINGMVC, and also add the dependency of the Thymeleaf template, the following is the simplest SPRINGMVC instance:
Package Cn.karent.controller;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.ui.Model;
Import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by Wan on 2017/1/17.
*/
@Controller
@RequestMapping ("/hello") public
class Hellocontroller {
@RequestMapping ("first") Public
String First (model model) {
model.addattribute ("Hello", "World");
return "First";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Thymeleaf template as follows, fist.html:
<! DOCTYPE html>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-data-jpa</artifactid>
</dependency>
<dependency>
<groupid >mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency >
1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
After adding dependencies, you need to configure some of the configuration required to connect to MySQL and create a application.properties:
spring.datasource.url = jdbc:mysql://localhost:3306/test Spring.datasource.username = root
Spring.datasource.password = Root Spring.datasource.driverClassName = com.mysql.jdbc.Driver # Specify the DBMS Spring.jpa.database = MYSQL # Show or not log for each SQL query Spring.jpa.show-sql = true # Hibernate DDL auto (Create, Create-drop, update) Spring.jpa.hibernate.ddl-auto = update # naming strategy SPRING.JPA