1.Springboot项目生成的目录
2.在demo下新建demoA
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoA {
@RequestMapping("/hello1")
public String hello1() {
return "hello World!";
}
}
2.在demo下新建demoB
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoB {
@RequestMapping("/hello2")
public String hello2() {
return "hello world2!";
}
}
3.DemoApplication 中写入main方法
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
4.运行程序
5.在浏览器中查看http://localhost:8080/hello1
6.到此OK了