问题:请求地址/username/resourceUrl/methodName,其中username可能有也可能没有,resourceUrl中会带/,这个时候要使用@PathVariable,不能正确匹配controller
解决思路:把resourceUrl处理成一个不带/的参数即可
1、约定好/替换方案,比如请求方把/全部替换为--
2、通过url编码解码处理 / 经过编码变成%2F 把resourceUrl编码后,这个时候发现还是不能请求到正确的方法,因为到spring时已经自动解码了。可以把%2F再编一次码变成%252F。%编码后是25
/**
*/abc/xiaoming/h5/user.json/get
*/
@ResponseBody
@RequestMapping(method=RequestMethod.POST ,value="/abc/{username}/{resourceUrl}/{methodName}")
public String dubboMock(HttpServletResponse response,@PathVariable String username,@PathVariable String resourceUrl,@PathVariable String methodName){
}
3、放弃使用PathVariable,手动去处理
/**
*/abc/xiaoming/h5/user.json/get
*/
@ResponseBody
@RequestMapping(method=RequestMethod.POST ,value="/abc/**")
public String dubboMock(HttpServletResponse response,HttpServletResponse request){
String url = request.getRequestURI();
//处理url
}
分享到:
相关推荐
SpringMVC@RequestMapping(重点)@RequestParam@PathVariable示例
主要介绍了SpringMVC中使用@PathVariable绑定路由中的数组的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
OA系统-springMVC/Mybatis/Mysql/Bootstrap OA系统-springMVC/Mybatis/Mysql/Bootstrap OA系统-springMVC/Mybatis/Mysql/Bootstrap
SpringMVC @ModelAttribute应用SpringMVC @ModelAttribute应用
1、访问地址:http://localhost:8080/springmvc/user/hello?userId=123456 2、配置步骤: 1)引入架包; 2)写controller类 3)写application-yg-servlet.xml 4)配置web.xml 3、不足之处 spring-webmvc-2.5.6...
NULL 博文链接:https://zhaoshunxin.iteye.com/blog/1166266
使用方法直接下载导入到自己的eclipse工具中,tomcat进行部署,访问地址:http://ip:port/springmvc02/toLogin.do;将login.jsp中的form表单中的action请求路径修改为LoginController类中的相应的@RequestMapping("/...
1.SpringMVC框架, 2.使用MYSQL数据库分读、写; 3.使用Log4j日志 4.详解数据提交和解析 文档地址:http://blog.csdn.net/sandyagor/article/details/51016885
@RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public void del(HttpServletRequest request, @PathVariable("id") Long id){ System.out.println(id); }
1、访问地址:http://localhost:8080/springmvc/user/hello?userId=123456 2、配置步骤: 1)引入架包; 2)写controller类 3)写application-yg.servlet.xml 4)配置web.xmlhttp://u.download.csdn.net/images...
今天小编就为大家分享快速解决SpringMVC @RequestBody 用map接收请求参数的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
springmvc2.5.6实现webservice 接口 带参数设置 1、访问地址:http://localhost:8080/springmvc/user/hello?userId=123456 ...3以上版本就支持@PathVariable注解,允许的话,建议采用SpringMVC4,增加了一些新特性
主要介绍了SpringMVC @ControllerAdvice使用场景,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
本文主要介绍了spring mvc中的@PathVariable获得请求url中的动态参数的代码。具有很好的参考价值,下面跟着小编一起来看下吧
springmvc实现乱码的处理,以及不同于单个的RequestMapping的配置,通过PathVariable的方式
public String demo(@PathVariable Long id){ ... } 通过@PathVariable就可以接受路径/login/{id}中的id值了。 From表单传值 先介绍模拟前台和实体类: 前台: 用户名: 密码: 实体类: 这里定义实体类需要...
springmvc对json支持
NULL 博文链接:https://bijian1013.iteye.com/blog/2310240
Maven+SpringMVC的入门级HelloWorld实例,简单了解Maven和SpringMVC整合