1.先新增一个接口类
package demo.controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class springHello {
@RequestMapping("/getUser")
@ResponseBody
String home() {
return "Hello World! 我是一个大帅哥,我是大飞哥";
}
}
2.新增扫包范围
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration //开启自动配置
@ComponentScan("demo.controller")
public class DemoApplication {
@RequestMapping("/getName")
String home() {
return "Hello World! 我是一个大帅哥";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
3.实际结果