Simple demo of spring boot

1. New project springboot.world

 

2.pom.xml to add parent dependencies

 

 

<parent>
	 <groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-parent</artifactId>
	 <version>1.5.2.RELEASE</version>
</parent>

    Add the parent dependency of spring boot, so that the current project is the spring boot project, spring-boot-starter-parent is a special starter, which is used to provide related Maven default dependencies

 

 

 3.pom.xml add web dependencies

 

 

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
</dependencies>

    After adding this, the following annotations can be used. As for why, it should be clear when you think about it with your butt. I will not describe it in detail here.

 

   @RestController

   @RequestMapping("/simple")

   ............etc

 

   4. Write a simple controller experience

 

 

package com.basic.demo;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * desc: simple controller
 * @date 2017-03-28 11:28:56
 * @author hone the dragon
 *
 */
@RestController
@RequestMapping("/simple")
public class SimpleController {

	@RequestMapping("/hello/{id}")
	public String hello(@PathVariable("id") Long id){
		return "Hello: "+id;
	}
}

    

 

    Project startup entry

    

package com.basic.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * desc: project startup entry
 * @date 2017-03-28 11:29:39
 * @author hone the dragon
 *
 */
@SpringBootApplication
public class App {
	
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

    Run the main method, so we start the project, what are you waiting for, test it out

 

 

    Enter the address: http://localhost:8080/simple/hello/666666

    

    The effect is as follows:

 

    success! ! ! Not much nonsense. crap now

 @SpringBootApplication is the core annotation of the spring boot project, the main purpose is to enable automatic configuration.

 The @SpringBootApplication annotation mainly combines @Configuration, @EnableAutoConfiguration, @ComponentScan

 

 Spring Boot will automatically scan the sibling package of the class where @SpringBootApplication is located, as well as the beans in the subordinate package

    

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326158384&siteId=291194637