@RequestMapping 注解

  1. @RequestMapping 是 Spring MVC 提供的核心注解,用来 将 HTTP 请求映射到具体的处理方法.
  2. 在 Spring Boot 中,它常用于 Controller 类,指定某个 URL 路径对应的方法.它的作用就是把 URL 和方法绑定起来,让请求能正确路由到对应的业务逻辑.

@SpringBootTest 注解

  1. @SpringBootTest 是 Spring Boot 提供的测试注解,用于在测试时启动完整的 Spring 应用上下文.

@RunWith 注解

  1. @RunWith 是 JUnit 4 提供的注解(org.junit.runner.RunWith), 它的作用是指定测试运行器(Runner),告诉 JUnit 使用哪个类来运行测试. 在 Spring Boot 测试中,通常会结合 SpringRunner 使用.

@Controller 注解

  1. @Controller 是 Spring MVC 提供的注解(位于 org.springframework.stereotype.Controller), 它的作用是标识一个类为控制层组件,让 Spring 容器在启动时将其识别为 Web 控制器,用于处理 HTTP 请求,负责接收请求、调用业务逻辑、返回视图或数据。

@RestController 注解

  1. @RestController 是 Spring Boot / Spring MVC 提供的注解,位于 org.springframework.web.bind.annotation.RestController. 它本质上是 组合注解:@Controller + @ResponseBody,它的作用是将类标识为控制层组件, 并且该类中所有方法的返回值都会直接写入 HTTP 响应体(Response Body), 而不是解析为视图.

@RequestMapping 注解

  1. @RequestMapping 是 Spring MVC 提供的核心注解,位于 org.springframework.web.bind.annotation.RequestMapping.它的作用是将 HTTP 请求映射到控制器方法或类, 即定义路由规则, 可以用在类上(定义统一前缀)和方法上(定义具体路径和请求方式).

@ExceptionHandler

  1. @ExceptionHandler 是 Spring MVC 提供的注解,位于 org.springframework.web.bind.annotation.ExceptionHandler. 它的作用是定义一个方法来专门处理某类异常,避免异常直接抛到前端.常用于 Controller 层 或 全局异常处理类.

@RequestParam

  1. @RequestParam 是 Spring MVC 提供的注解,位于 org.springframework.web.bind.annotation.RequestParam. 它的作用是将 HTTP 请求中的参数绑定到控制器方法的形参上(即将 URL 或表单中的参数值自动注入到方法参数中), 常用于处理查询参数(Query Parameter)或表单参数.

@Autowired

  1. @Autowired 是 Spring 提供的一个依赖注入注解,其作用是自动装配. Spring 会根据类型自动查找并注入合适的 Bean 到目标对象中.