本文共 1458 字,大约阅读时间需要 4 分钟。
第一次接触SpringBoot,根据官网在pom.xml中导入相应依赖后,首先,新建controller包,在其中写HelloController类:
import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;@Controllerpublic class HelloController { @ResponseBody @RequestMapping("/hello")public String sayHello() { return "hello,This is my first Spring Boot.";}}
再写MyBootRun类,用它的主方法来运行Boot:
package com.bit.springboot.po;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class MyBootRun { public static void main(String[] args) { SpringApplication.run(MyBootRun.class,args); }}
这时执行主方法,控制台的输出为:
转载地址:http://zdjh.baihongyu.com/