RequestMapper使用

使用方式

@RequestMapper("/")指定访问路径
@RequestMapper(value="/
")用于指定请求路径url,和path属性的作用一样
@RequestMapper(value="/",method={RequestMethod.GET}) 指定访问方式为GET请求,默认为所有请求方式
@RequestMapping(path = "/
",params = {“username”})params 属性指定访问接口必须传的属性
@RequestMapping(path = “/hello”,headers = {“Accept”})headers请求中必须
包含Accept该请求头

 @RequestMapping(path = "/hello")
    public String satHello(){
        System.out.println("Hello springMVC");
        return "success";
    }

@RequestMapping代码块

package org.springframework.web.bind.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;

//ElementType.TYPE 作用于描述类、接口(包括注解类型) 或enum声明
//ElementType.METHOD:用于描述方法
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping {
    String name() default "";

//@AliasFor---别名
    @AliasFor("path")
    String[] value() default {};

    @AliasFor("value")
    String[] path() default {};

// method() -- 指定访问方式
    RequestMethod[] method() default {};

    String[] params() default {};

    String[] headers() default {};

    String[] consumes() default {};

    String[] produces() default {};
}

@Target 说明了Annotation所修饰的对象范围:Annotation可被用于 packages、types(类、接口、枚举、Annotation类型)、类型成员(方法、构造方法、成员变量、枚举值)、方法参数和本地变量(如循环变量、catch参数)。在Annotation类型的声明中使用了target可更加明晰其修饰的目标。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值