springboot学习(一)
本人初学springboot写的第一个入门代码Helloworld
一、创建一个maven项目
二、在pom.xml文件中导入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
三、创建一个HelloWorldMainApplication类启动项目
package com.lp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/* @SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用 */
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
// 将Spring应用启动起来
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}
四、完善controller
编写HelloController类
package com.lp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "hello world";
}
}
五、大功告成
可以在浏览器中输入http://localhost:8080/hello进行测试
今天是初学springboot的第一天,后续会更新一些新的学习成果