package com.huc.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
//@Controller
// 将类标识为Controller层用来接受请求
//@ResponseBody
// 默认返回的是一个页面对象,当使用这个注解之后,可以返回普通对象
@RestController // @RestController=@Controller+@ResponseBody
// 相当于既能标识为Controller层又能返回普通对象
public class TestController {
@RequestMapping("demo") // 通过括号中的映射名来决定,发送过来的请求调用的是哪个方法
public String test() {
System.out.println("123");
return "success";
}
@RequestMapping("demo2")
public String test2(
// 当发送过来的请求携带参数时,通过括号中的映射名来决定,对应的是哪个参数
@RequestParam("name") String name,
@RequestParam("age") Integer age) {
System.out.println("1111");
return "name:" + name + "-" + "age:" + age;
}
}
SpringBoot中常见注解@Controller@ResponseBody@RestController@RequestMapping@RequestParam
最新推荐文章于 2023-03-22 23:24:04 发布