学习springboot(一)——helloworld

1、设置好idea环境
2、设置好maven环境
3、创建一个hello的maven工程;
4、修改pom,添加spring boot依赖:

org.springframework.boot
spring-boot-starter-parent
2.0.0.RELEASE

上述内容用于引入spingboot所有需要的基础依赖;

5、添加main 类;
6、在main类上添加 @SpringBootApplication 以告诉系统这是个spring boot应用
7、在main方法里,添加 SpingApplication.run(A.class, args);
如:

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

以上,完成了一个spring boot的搭建;通过edit - configragiton ,以spring boot模板启动,即可;
以下,是需要通过浏览器访问spring boot程序并返回值,需要添加web依赖(也即是SPRING MVC的依赖);
8、

org.springframework.boot
spring-boot-starter-web


上述内容用于引入spingboot所有需要的web依赖;
9、编写一个Hello类,添加@Controller注解
添加say方法,添加 @RequestMapping,设置返回@Responsebody,如:

@Controller
public class HellowordController {

@RequestMapping("/hello")
public @ResponseBody String sayHello(){
    return "hello world";
}id

@RequestMapping("/hello/{id}")
public @ResponseBody String say(@PathVariable String id){
    return "hello world";
}

}

10、启动程序,通过浏览器访问 127.0.0.1/hello 即可看到浏览器呈现 hello world

你可能感兴趣的:(学习springboot(一)——helloworld)