What is springboot?
Spring Boot is commonly known as microservices. Spring Boot is a new framework provided by the Pivotal team. It is designed to simplify the initial construction and development process of new Spring applications. The framework uses a specific way to configure it, so that developers no longer need to define boilerplate configurations. In this way, Spring Boot is committed to becoming a leader in the booming rapid application development.
1. Create a new maven project
Select workspace first
Click [next]
Directly default, click [next]
Fill in groupid, etc. ~ and then [finish], and the entire new construction project is over here.
2. Introduce related jar packages
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
Here we explain that we only referenced 2 jar packages, which actually contain a lot of things, such as spring-boot-starter-web, after we opened it through the compressed package.
Check the pom file inside to see the content shown below. It references many jars such as spring web and json jar packages.
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> </dependency> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> </dependency> </dependency>
3. Write program entry class
package com.springbooot2;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * Hello world! * */@SpringBootApplicationpublic class App { public static void main(String[] args) throws Exception { SpringApplication.run(App.class, args); }}Here, @SpringBootApplication is to let spring scan recognize it and tell him that I am a program entry class.
4. Write a request response class
package com.springbooot2;import org.springframework.steretype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody; @Controllerpublic class FristBlood { @RequestMapping("/FristBlood") @ResponseBody public String hello() { return "dont worry, be happy!<br/><br/> <input type=/"submit/" value=/"ok/" />"; }}Here is an explanation
@Controller Request processing controller class.
@RequestMapping Those who are familiar with spring should be familiar with it. This is a spring thing, url mapping.
@ResponseBody response method, our response information will be automatically converted into json information and returned to the foreground page
The whole code is finished here, which is much simpler than building a framework like ssh or ssm before. If we have that kind of thing, we just need to send an email. Or a simple service, it can be said that it is very convenient to use springboot.
5. Test code
Start the program, open the browser, enter: http://localhost:8080/FristBlood
The response result of the request page is as follows.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.