Spring Boot---(1)新建Spring Boot 项目_java

至此,项目就创建完成了。我们如果在启动类上加上@RestController (具体用法后面会介绍:​​Spring Boot---(5)SpringBoot常用注解​​),然后写个接口,就可以访问了,如下:

 

package com.jd;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Demo1Application {

public static void main(String[] args) {
SpringApplication.run(Demo1Application .class, args);
}

@RequestMapping(value = "testGood",method = RequestMethod.GET)
public String testGood(String name){
return "Welcome to tmall Mr."+ name;
}
}

在浏览器访问:

 

Spring Boot---(1)新建Spring Boot 项目_spring_02