关于requestMapping 进行url映射实现小小知识点 以及如何获取请求的url中的参数...

requstMapping 用来处理url映射  可以作用在controller类上  也可以作用在方法上

经常使用的方式  通过接收一种映射关系

   @RequestMapping("/deleteMainMultipleMessages")
    public ModelAndView deleteMainMultipleMessages(String id[]){
        for (int i = 0; i < id.length; i++) {
            service.delete(id[i]);
        }
        return new ModelAndView("redirect:/user/home");
    }

其实requstMapping可以接收多个请求方式   通过localhost:8080/hello  与localhost:8080/hi 都可以访问同一个请求方法

  @RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET)
    public String say(){

       return gril.getName();
    }

 

在requesetMapping 可以指定method 请求的类型比如get  post 等

同时也可以忽略让服务器自己判断  但是不希望这样做  通常我们希望指定请求方式的做法来做  这样是安全的  post get 等都是对应不同业务情况的

以前都没注意过今天记录一下。。。。。

 

@PathVariable 获取url中的数据

 请求方式:http://localhost:9001/hello/34

 @RequestMapping(value = {"/hello/{id}"},method = RequestMethod.GET)
    public String say(@PathVariable(value = "id")String id){

       return id;
    }

也可以写在前面  http://localhost:9001/34/hello

 @RequestMapping(value = {"/${id}/hello"},method = RequestMethod.GET)
    public String say(@PathVariable(value = "id")String id){

       return id;
    }

 

@RequstParam 获取请求参数的值

@getMapping 组合注解

 

转载于:https://www.cnblogs.com/lwdmaib/p/9897908.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值