请求参数中的特殊字符

时间:2017-02-24 09:15:27

标签: java spring rest

在我的基于REST的API(spring boot& REST)中,我的GET调用有以下参数

@RequestParam(required = false ) String name, @RequestParam(required = false, defaultValue = "1") Long page,
            @RequestParam(required = false, defaultValue = "20") Long pageSize.

当用户使用某些特殊字符调用我的GET方法时,发生错误。

请求格式如下:

http://localhost:8015/accounts/1/things/?name=%23%$25%2$3%5e

在我的控制器中,有时名称为空,有时我会收到以下错误

2017-02-24 14:31:29.396 -DEBUG [nucleus-thing-service,6cae9c64f94df6a6,6cae9c64f94df6a6,true] 4288 --- [nio-8015-exec-4] c.c.n.thing.controller.ThingsController  : Log after calling - com.cantiz.nucleus.thing.controller.ThingsController.getAll
2017-02-24 14:31:29.398 -ERROR [nucleus-thing-service,6cae9c64f94df6a6,6cae9c64f94df6a6,true] 4288 --- [nio-8015-exec-4] c.c.n.thing.controller.ThingsController  : Log after throwingcom.cantiz.nucleus.thing.controller.ThingsController.getAllException : java.util.UnknownFormatConversionException: Conversion = '#'
    at java.util.Formatter.checkText(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)

0 个答案:

没有答案