在@RestController的方法中,如果路径参数带.(点号)会截断,如何配置?

RestController对应代码:
    @RequestMapping(value = "/info/email/{email}",method = RequestMethod.GET)
public User getInfoByEmail(@PathVariable String email){
User user = userRepository.findByEmail(email);
return user;
}


请求方式:
http://localhost:8080/api/v1/user/info/email/dujc1018@gmail.com
 
断点显示:
C.png

 
已邀请:

杨小强 - http://www.jianshu.com/u/997ed7c05f59

赞同来自: mercyblitz wayne baiqirui zxddeveloper

mercyblitz - mercyblitz

赞同来自: wayne

@RestController public class RestControllerDemo extends WebMvcConfigurerAdapter { @RequestMapping(value = "/info/email/{email}", method = RequestMethod.GET) public Object getInfoByEmail(@PathVariable String email) { return email; } 
 
public void configurePathMatch(PathMatchConfigurer configurer) {     configurer.setUseSuffixPatternMatch(false); 

 
}

PathMatchConfigurer.png

 

wayne

赞同来自:

多谢小马哥和@杨小强的帮助,已经解决
这里给个全局的解决方案:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
* Created by Administrator on 2017/7/10 0010.
*/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}
}

通过这个问题,发现需要对WebMvcConfigurerAdapter做一些了解,一些问题可以从源头就解决掉
 
参见:http://blog.netgloo.com/2015/0 ... dots/

黄老邪 - IT民工

赞同来自:

马克,学习了

要回复问题请先登录注册