至此,项目就创建完成了。我们如果在启动类上加上@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;
}
}