学习springboot(一)——helloworld

1、设置好idea环境
2、设置好maven环境
3、创建一个hello的maven工程;
4、修改pom,添加spring boot依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
上述内容用于引入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、 <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
上述内容用于引入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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容