【问题标题】:Springmvc RequestMapping accept any character in any languageSpringmvc RequestMapping 接受任何语言的任何字符
【发布时间】:2016-06-28 05:36:47
【问题描述】:

我需要在@RequestMapping 值中使用正则表达式,以便它可以接受日文字符和英文字符。

我试过了-

@RequestMapping(value = "/Attendance_Report{[a-z0-9_\\p{Hiragana}\\p{Katakana}]+}", method = RequestMethod.GET)

当 URL 中存在日文字符时,它不起作用。但以下内容在请求 url 中没有日文字符 -

@RequestMapping(value = "/Attendance_Report{[a-z0-9_]+}", method = RequestMethod.GET)

我应该在 value 属性中准确地输入什么来满足我的要求?

【问题讨论】:

    标签: java regex spring spring-mvc


    【解决方案1】:

    我认为您应该保持原样(即'/Attendance_Report'),如下所示:

    @RequestMapping(value = "/Attendance_Report", method = RequestMethod.GET)
    

    为了在 URI 中同时接受英文 (ISO-8859-1) 和日文 (UTF-8) 字符,我认为这是应用程序服务器(例如 Tomcat)配置的问题。例如,如果你部署在 Tomcat 上,你应该将URIEncoding 设置为"UTF-8",像这样。

    <Connector URIEncoding="UTF-8" ..>
    

    【讨论】:

    • ...... ......我试过这个和上面说的RequestMapping。但它提供 HTTP 400。
    • 您的请求网址是什么样的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 2014-06-27
    • 2013-01-18
    • 2013-08-29
    • 2014-03-05
    • 2012-03-07
    相关资源
    最近更新 更多