Spring boot 参数拼在访问路径中,如果参数带 点(符合)后面数据取不到

Spring MVC路径匹配配置
本文介绍如何通过重写Spring MVC的configurePathMatch方法并设置configurer.setUseSuffixPatternMatch(false)来解决路径匹配问题,确保后台能正确获取带有完整邮箱地址的参数。


在配置类中 重写WebMvcConfigurerAdapter 的  configurePathMatch  方法,设置configurer.setUseSuffixPatternMatch(false);  即可解决。

直接上代码:

//配置类

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Autowired
private AuthInterceptorService authInterceptorService;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new GateInterceptor());
registry.addInterceptor(new AuthInterceptor(authInterceptorService));


}
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}


}


//前端代码

var Email =‘54349**@qq.com’

  Tools.ajax({
        url: Config.basePath + "/web/verify/AlterEmailSendNewLink/+Email ,
        type: "get",
        data: "",
        success: function (data) {

......

}

})

如果 不加代码,后台只能取到 Email= 54349**@qq

       加过代码后,后台取到值 Email= 54349**@qq.com

(完)

在@RequestMapping的value中使用SpEL来表示,value中的{version}换成{version:.+}。

@RequestMapping(value="android/download/{version:.+}",method=RequestMethod.GET)public void download(HttpSession session,HttpServletResponse response,@PathVariable("version")String version){}
  • 1

终于可以再一次愉悦地进行玩耍了。


Spring Boot中,你可以通过以下步骤自定义静态资源(如HTML、CSS、JS文件)的访问路径: 1. **修改web.xml**:虽然Spring Boot默认不使用`web.xml`,但在某些情况下(如整合第三方库),你可以在项目的`src/main/webapp/WEB-INF`目录下添加一个自定义的`web.xml`文件,然后在其中配置资源过滤器。例如: ```xml <filter> <filter-name>ResourceFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetBeanName</param-name> <param-value>resourceHandlerMapping</param-value> </init-param> </filter> <filter-mapping> <filter-name>ResourceFilter</filter-name> <url-pattern>/resources/**</url-pattern> </filter-mapping> ``` 这里配置了一个名为`ResourceFilter`的过滤器,其目标bean是`resourceHandlerMapping`,这将重定向所有以`/resources/`开头的请求到Spring Boot的静态资源处理器。 2. **使用Spring MVC配置**:另一种方法是利用Spring MVC的资源配置,比如在`spring-boot-starter-web`的配置类(通常是`Application.java`或`Main.java`)里,可以添加一个`ResourceHandlerRegistry`实例,调整静态资源前缀: ```java @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/custom-path/**") .addResourceLocations("classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"); } } ``` 这里的`/custom-path/**`将是新的资源访问路径前缀,`classpath:`后面路径是指向项目中的静态资源目录。 3. **使用Spring Cloud Spring actuator**:如果你正在使用Spring Cloud和Spring Boot Actuator,记得要排除管理端的资源,以免它们覆盖静态资源路径。 注意:尽量保持路径简洁明了,避免与应用程序内部的其他URL冲突。在生产环境中,还可以考虑使用CDN服务来缓存和分发静态资源,提高性能。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值