package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/enter")
public class EnterController {
//get请求 无参数
//http://localhost:8080/springmvc/enter/demo1
@RequestMapping("/demo1")
public void demo1(){
System.out.println("demo1");
//结果 demo1
}
//get 请求 有参数
//http://localhost:8080/springmvc/enter/demo2/001
@RequestMapping("/demo2/{serverCode}")
public void demo2(@PathVariable String serverCode){
System.out.println(serverCode);
// 结果 001 后边参数可以变动, 是按照顺序排列的
}
//get 请求 有参数
//http://localhost:8080/springmvc/enter/demo2/001
@RequestMapping("/demo3/{serverCode}/{pathcode}")
public void demo3(@PathVariable String serverCode,@PathVariable String pathcode){
System.out.println(serverCode + " " + pathcode);
//001 123
// 结果 001 后边参数可以变动, 是按照顺序排列的
}
//post请求 工具模拟 jmeter
//http://localhost:8080/springmvc/enter/demo4 post
//content-Type application/json
@RequestMapping("/demo4")
public void demo4(@RequestBody String requestBody){
System.out.println(requestBody);
//{"userId":"123456"}
}
//以上为纯后端开发
}
返回直接返回string数据就可以