Raj*_*Raj 6 java rest spring spring-mvc
在我使用Spring Framework开发的REST API中,我有一个Rest端点接收Two Double值,Rest Call是:http:// localhost:8080/restapp/events/nearby/12.910967/77.599570
这里,第一个参数(双数据类型)即12.910967我能正确接收,即12.910967.但是第二个参数,即77.599570,我只能在小数点截断后得到77.0的数据.
我的REST后端是:
@RequestMapping(value = "/nearby/{lat}/{lngi}", method = RequestMethod.GET, produces = "application/json")
public List<Event> getNearByEvents(@PathVariable("lat") Double lat, @PathVariable("lngi") Double lngi, HttpServletResponse response) throws IOException
Run Code Online (Sandbox Code Playgroud)
如何在REST api中接收双数据类型?
更新您的代码如下 - 请注意,它{lngi:.+}指定了一个正则表达式,这意味着某些字符将出现在帖子中.
@RequestMapping(value = "/nearby/{lat}/{lngi:.+}", method = RequestMethod.GET, produces = "application/json")
public List<Event> getNearByEvents(@PathVariable("lat") Double lat, @PathVariable("lngi") Double lngi, HttpServletResponse response) throws IOException
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1471 次 |
| 最近记录: |