我有一个RESTful服务。这包含两个参数:开始日期和结束日期。
如果我使用@RequestParam注释,我就得到了我需要的东西。但是,如果我使用@QueryParam,我注意到即使在传递时,它也始终显示为null。
这是我的资源:
@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);
}这是我的刀:
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();
}
}任何帮助都将不胜感激。可能是很明显的事
发布于 2016-04-04 01:06:28
如果我使用
@RequestParam注释,我就得到了我需要的东西。但是,如果我使用@QueryParam,我注意到即使在传递时,它也始终显示为null。
因为您使用的是Spring,它与@QueryParam所使用的JAX没有任何关联。Spring使用@RequestParam。如果要使用Spring,我建议您摆脱JAX依赖关系,这样您就不会对可以使用和不能使用的东西感到困惑。
发布于 2019-04-08 14:47:32
将@QueryParam("end-date")替换为@QueryParam("endDate")。这会管用的。但是,我建议您使用来自org.springframework.web.bind.annotation的org.springframework.web.bind.annotation,其原因在Paul的回答中得到了很好的解释。
https://stackoverflow.com/questions/36392717
复制相似问题