我有一個RESTful服務。這需要兩個參數:開始日期和結束日期。@QueryParam始終顯示爲空
如果我使用@RequestParam註釋,我得到我需要的。但是如果我使用@QueryParam,我注意到它即使在傳遞時也總是顯示爲空。
這裏是我的資源:
@RequestMapping(value = "/usage-query", method = RequestMethod.GET)
@ApiOperation(value = "Available Sessions - JSON Body", notes = "GET method for unique users")
public List<DTO> getUsageByDate(@QueryParam("start-date") final String startDate,
@QueryParam("end-date") String endDate)
throws BadParameterException {
return aaaService.findUsageByDate2(startDate, endDate);
}
那麼這裏就是我的服務:
List<DTO> findUsageByDate(String startDate, String endDate) throws BadParameterException;
那麼這裏就是我的服務實現:
public List<DTO> findUsageByDate(String startDate, String endDate) throws BadParameterException {
return aaaDao.getUsageByDate(startDate, endDate);
}
這裏是我的DAO:
List<DTO> getUsageByDate(String startDate, String endDate) throws BadParameterException;
這裏是我的DAO實現:
@Override
public List<DTO> getUsageByDate(String startDate, String endDate) throws BadParameterException {
StringBuilder sql = new StringBuilder(
"select * from usage where process_time >= :start_date");
if(endDate!= null)
{
sql.append(" and process_time < :end_date");
}
sql.append(" limit 10");
System.out.println(sql.toString());
SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("start_date", startDate)
.addValue("end_date", endDate);
try {
return jdbcTemplate.query(sql.toString(), namedParameters,
new BeanPropertyRowMapper<DTO>(AAAUsageDTO.class));
} catch (EmptyResultDataAccessException e) {
throw new BadParameterException();
}
}
任何幫助將不勝感激。可能有些東西明顯
以及您要調用requestparam和query param的服務端點是什麼? – Sanj
對不起,我把代碼放在了需要的位置:-)這裏是:GET/v1/usage/usage- query?start-date = 2016-01-01; end-date = 2016-03- 01 HTTP/1.1 – Xathras
在開始日期和結束日期之間有一個&符號? – Sanj