关于注解的使用说明

@Target注解
声明可以使用的对象
@Target{Elemtype.xxx}
Elemtype 为枚举类

public enum ElementType {
   //类接口或者泛型的声明
    TYPE,

  //域声明
    FIELD,

//方法声明
    METHOD,

//参数声明
    PARAMETER,

//构造器声明
    CONSTRUCTOR,

//本地变量声明
    LOCAL_VARIABLE,

 //声明
    ANNOTATION_TYPE,

//包
    PACKAGE,

//参数
    TYPE_PARAMETER,

//使用
    TYPE_USE
}

@Retention注解:注解的存在位置
使用@Retention{RetentionPolicy.xxx}
RententionPolicy枚举类

public enum RetentionPolicy {
    /**
     * Annotations are to be discarded by the compiler.源文件
     */
    SOURCE,

    /**
     * Annotations are to be recorded in the class file by the compiler
     * but need not be retained by the VM at run time.  This is the default
     * behavior.class文件
     */
    CLASS,

    /**
     * Annotations are to be recorded in the class file by the compiler and
     * retained by the VM at run time, so they may be read reflectively. 运行时
     *
     * @see java.lang.reflect.AnnotatedElement
     */
    RUNTIME
}

@Documented 注解会把加该注解的对象加入到javadoc下
@Component 注入到Spring工厂中去
@Aspect Aop的面向切面
@Slf4j 日志文件的注解
@autowried自动注入对象 ,必须再Spring 工厂中注册
@PointCut()
里面可以“@annocation(注解名称)”来声明切入的地方,也可用传统的execute的方式
@Before @around 一个是环绕一个是之前 用execute的方式可以不用单独写@pointcut,否则则是该方法 调用@Around(“xxx”)…xxx为pointcut后的方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
@Mapping注解在Spring MVC框架中有着广泛的应用,它可以用于将HTTP请求映射到处理程序类或处理程序方法上。具体的使用方式和说明如下: 1. 用于类级别 在类级别上使用@Mapping注解表示该类中所有方法的映射路径的公共前缀。例如: ``` @Controller @RequestMapping("/user") public class UserController { // ... } ``` 上述代码表示UserController类中所有方法的映射路径都以/user为前缀。 2. 用于方法级别 在方法级别上使用@Mapping注解表示该方法的具体映射路径。例如: ``` @Controller @RequestMapping("/user") public class UserController { @RequestMapping("/list") public String listUsers(Model model) { // ... } } ``` 上述代码表示listUsers方法的映射路径是/user/list。 3. 指定HTTP请求方法类型 @Mapping注解可以指定HTTP请求的方法类型,例如: ``` @RequestMapping(value = "/users", method = RequestMethod.GET) public List<User> getUsers() { // ... } ``` 上述代码表示getUsers方法只接受GET请求。 4. 指定请求参数和请求头信息 @Mapping注解可以指定HTTP请求的参数和头信息,例如: ``` @RequestMapping(value = "/user", params = "id=1", headers = "content-type=text/plain") public String getUser() { // ... } ``` 上述代码表示getUser方法只接受id参数值为1,content-type头信息为text/plain的HTTP请求。 5. 支持Ant风格的URL路径匹配 @Mapping注解支持Ant风格的URL路径匹配,例如: ``` @RequestMapping("/user/*") public String handleRequest(HttpServletRequest request, HttpServletResponse response) { // ... } ``` 上述代码表示匹配以/user/开头的所有URL路径。 总之,@Mapping注解是Spring MVC框架中非常重要的注解,它可以帮助我们将HTTP请求映射到对应的处理程序方法上,从而实现请求处理和响应的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值