Springboot的一个HelloWorld
工具:idea、java8
一步步来~
启动类:
package com.aijiajia.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Controller; @Controller @SpringBootApplication @ComponentScan(basePackages = "com.aijiajia.*") public class SpringbootDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringbootDemoApplication.class, args); System.out.println("SpringBoot启动成功啦"); } }
新建一个测试Controller:
package com.aijiajia.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class TestController { @RequestMapping("/test") @ResponseBody public String Test(){ return "访问成功"; } }
接着启动启动类
打开浏览器 访问:http://localhost:8080/test
OK 拜拜~