Springboot Introduction Demo
Spring Boot is a new framework provided by the pivotal team designed to simplify the initial setup and development of new spring applications. The framework uses a specific approach to configuration, which eliminates the need for developers to define boilerplate configurations. In this way, Spring boot is committed to becoming a leader in the burgeoning field of rapid application development (rapid application development).
Features 1. Create a standalone spring application 2. Embedded Tomcat, no need to deploy war file 3. Simplifies MAVEN configuration 4. Auto-Configure Spring 5. Provides production-ready features such as indicators, health checks and external configuration 6. Absolutely no code generation and no configuration required for XML
Springboot Profile Address:
Https://baike.baidu.com/item/Spring%20Boot/20249767?fr=aladdin#1
1. Learning Springboot requires a basic knowledge of SSM
2. Springboot is developed in MAVEN environment needs MAVEN knowledge to pave the groundwork
3. Development tools (idea, Eclipse)
4. Actual development steps:
1.) Create a MAVEN project
2.) Maven is a Web project
3.) Refine the directory structure created by Maven
4.) Modify the Pom.xml file
1<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"2xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >3<modelVersion>4.0.0</modelVersion>4<groupId>dt55</groupId>5<artifactId>springboot1</artifactId>6<packaging>war</packaging>7<version>0.0.1-SNAPSHOT</version>8<NAME>SPRINGBOOT1 Maven webapp</name>9<url>http://maven.apache.org</url>Ten One<!--the dependencies required to configure spring boot A<parent> -<groupId>org.springframework.boot</groupId> -<artifactId>spring-boot-starter-parent</artifactId> the<version>1.5.10.RELEASE</version> -</parent> - -<dependencies> +<!--spring Boot related start-up -<dependency> +<groupId>org.springframework.boot</groupId> A<artifactId>spring-boot-starter-web</artifactId> at</dependency> - -<!--hot Deployment-- -<dependency> -<groupId>org.springframework.boot</groupId> -<artifactId>spring-boot-devtools</artifactId> in<optional>true</optional> -<scope>true</scope> to</dependency> + -<!--log4j-- the<dependency> *<groupId>org.springframework.boot</groupId> $<artifactId>spring-boot-starter-log4j2</artifactId>Panax Notoginseng</dependency> - the<!--using the Jasper engine to parse the JSP-- +<dependency> A<groupId>org.apache.tomcat.embed</groupId> the<artifactId>tomcat-embed-jasper</artifactId> +<scope>provided</scope> -</dependency> $ $<!--JSP Support-- -<!--servlet dependency. - -<dependency> the<groupId>javax.servlet</groupId> -<artifactId>javax.servlet-api</artifactId>Wuyi<scope>provided</scope> the</dependency> -<dependency> Wu<groupId>javax.servlet</groupId> -<artifactId>jstl</artifactId> About</dependency> $ -<!--spring Boot integration mybatis-- -<dependency> -<groupId>org.mybatis.spring.boot</groupId> A<artifactId>mybatis-spring-boot-starter</artifactId> +<version>1.3.0</version> the</dependency> - $<!--MySQL-- the<dependency> the<groupId>mysql</groupId> the<artifactId>mysql-connector-java</artifactId> the</dependency> - in</dependencies> the the<build> About<plugins> the<plugin> the<groupId>org.springframework.boot</groupId> the<artifactId>spring-boot-maven-plugin</artifactId> +<configuration> -<!--without this configuration, Devtools does not take effect-- the<fork>true</fork>Bayi</configuration> the</plugin> the</plugins> -<finalName>springboot1</finalName> -</build> the</project>
5.) Modify the port number to create a application.properties file
1 server.port=8888
6.) Configure Data source information to configure the data source in the Application.properties file
1 spring.datasource.driver-class-name=com.mysql.jdbc.Driver2 Spring.datasource.url=jdbc:mysql:///dt553 spring.datasource.username=root 4 Spring.datasource.password=root
7.) Test the code:
1 /**2 * Project name:springboot13 * File Name:FrontController.java4 * Package Name:cn.java.controller.front5 * Date: 5:21:57 pm6 * Copyright (c) 2018, Bluemobi All rights Reserved.7 *8 */9 Ten PackageCn.java.controller.front; One A Importjava.util.List; - ImportJava.util.Map; - the ImportOrg.mybatis.spring.annotation.MapperScan; - Importorg.springframework.beans.factory.annotation.Autowired; - Importorg.springframework.boot.SpringApplication; - Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration; + ImportOrg.springframework.context.annotation.ComponentScan; - ImportOrg.springframework.stereotype.Controller; + Importorg.springframework.web.bind.annotation.RequestMapping; A ImportOrg.springframework.web.bind.annotation.ResponseBody; at - ImportCn.java.service.FrontService; - - /** - * Description: <br/> - * Date: PM 5:21:57 <br/> in * - * @authorChu Kaixin to * @version + * @see - */ the @Controller * @EnableAutoConfiguration $@ComponentScan (value = {"Cn.java.controller.*", "Cn.java.service.impl") })Panax Notoginseng@MapperScan (value = "Cn.java.mapper") - Public classFrontcontroller { the + @Autowired A PrivateFrontservice Frontservice; the +@RequestMapping ("/index") - @ResponseBody $ PublicStringGetLogin () { $ return"Hello World!!!!!"; - } - the Public Static voidMain (string[] args) { - //start the Springboot frameWuyiSpringapplication.run (Frontcontroller.class, args); the } - Wu}
This simple operation is much simpler than the SSM.
Let's try it.
Springboot Introduction Demo