SpringBoot environment to build a graphic tutorial, springboot to build a graphic
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 setup and development process of new Spring applications. The framework uses a specific method for configuration, so that developers no longer need to define the configuration of the template. In this way, Spring Boot is committed to becoming a leader in the rapidly developing rapid application development Field.
1. Create a maven Project
Select workspace first
Click next]
By default, click next]
Enter groupid and so on ~ Then click finish. The entire new project is created here.
2. Introduce relevant 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>
It seems that we only referenced two jar packages, which contain many things, such as spring-boot-starter-web.
You can see the following content in the pom file. It references a lot of jar files like 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-webmvc</artifactId> </dependency> </dependencies>
3. Programming Portal
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 used to let spring scan identify and tell him that I am a program entry class.
4. Write a request response class
package com.springbooot2;import org.springframework.stereotype.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\" />"; }}
It is described here
@ Controller: request processing Controller class.
@ RequestMapping should be familiar with spring. This is spring and url ing.
@ ResponseBody: The response information is automatically converted to json and returned to the front-end page.
The entire code is finished here, which is much easier than building an ssh or ssm framework. If we have one, we only need to send an email. Or a simple service, springboot is convenient.
5. Test code
Start the program, open the browser, and enter: http: // localhost: 8080/FristBlood
The response result of the request page is shown in.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.