本文介绍了如何在REST API中将日期(dd/MM/yyyy HH:mm)传递为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个REST API,在其中我将日期作为URL参数传递.日期格式为dd/MM/yyyy HH:mm ;REST API URL是

I am trying to write a rest api in which I am passing date as a URL parameter.Date formate is dd/MM/yyyy HH:mm;REST API URL Is

公共静态最终字符串GET_TestDate ="/stay/datecheck?dateCheckIn = {dateCheckIn}";

休息方式"为

     @RequestMapping(value = HotelRestURIConstants.GET_TestDate, method = RequestMethod.GET)
        public @ResponseBody String getDate(@PathVariable("dateCheckIn")  @DateTimeFormat(iso= DateTimeFormat.ISO.DATE) String dateCheckIn) {
            logger.info("passing date as a param");
            String str="date"+dateCheckIn;
            return str;
        }

但是在使用REST客户端调用此api时,出现 404错误.这是REST URL

but when am calling this api using REST client I am getting 404 error.Here is REST URL

http://localhost:8089/stay/datecheck?dateCheckIn="28/01/2016 19:00"

推荐答案

使用%20代替空格.可以使用%2F而不是斜杠.但是,获得该值后,您必须解码(将%20转换为空格,将%2F转换为斜杠).代替冒号,使用%3A.您在此处有一个URL编码表: http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

Instead of space, use %20. Instead of slash, you can use %2F. But, you have to decode (transform %20 to space and %2F to slash) after you get the value. Instead of colon, use %3A. You have an URL enconding table here: http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

最后一个提示:不要使用引号.

The last hint: don't use quotes.

尝试类似的东西:

http://localhost:8089/stay/datecheck?dateCheckIn=28%2F01%2F2016%2019%3A00

记住要对其进行解码.

类似的东西: String result = java.net.URLDecoder.decode(url,"UTF-8");

这篇关于如何在REST API中将日期(dd/MM/yyyy HH:mm)传递为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:30