springboot 学习笔记(一)

1.首先到 http://start.spring.io/ 下载springboot示例

2.导入到idea 中, 选择 maven方式导入

3.在pom中新增web模块支持

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

4.在工程中新建一个目录叫做 

com.myspringboot.study

5.在新建的目录下新建一个controller

@RestController
@SpringBootApplication
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello world";
    }

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

之后直接以main方法启动

2018-05-12 19:34:04.256  INFO 17744 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-12 19:34:04.427  INFO 17744 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-12 19:34:04.475  INFO 17744 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

控制台输出以上信息证明服务启动成功,可以进行访问了。 浏览器输入 http://localhost:8080/hello

可以发现springboot非常方便快捷的建立一个web项目。

猜你喜欢

转载自my.oschina.net/u/1178126/blog/1811382