我正在使用Spring REST API端点创建Spring启动服务。但我被困在一个非常简单的休息电话中。我的休息控制器如下:
@RestController
@RequestMapping(value={"/reportservice"})
public class ReportingMessageController {
@Autowired
private ReportService reportService;
@RequestMapping(value = {"/reports" }, method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<ResponseMessage> getReport(@RequestParam(value="eaid", required=true) String eaid,
@RequestParam(value="source", required=false) String source,
@RequestParam(value="userid", required=false) String userid,
@RequestParam(value="org", required=false) String org,
@RequestParam(value="startdate", required=true) Date startDate,
@RequestParam(value="enddate", required=true) Date endDate,
@RequestParam(value="page", required=false) int pageid){
ReportQueryParams params = new ReportQueryParams();
params.setEaid(eaid);
params.setSid(sid);
params.setSource(source);
params.setUserid(userid);
params.setOrg(org);
params.setStartdate(startDate);
params.setEnddate(endDate);
params.setPageid(pageid);
System.out.println(params);
ResponseMessage response = reportService.getReports(params);
return new ResponseEntity<ResponseMessage>(response, HttpStatus.OK);
}
}
服务类是:
@Component
public class ReportService {
public ResponseMessage getReports(ReportQueryParams params){
return new ResponseMessage();
}
}
ResponseMessage类是简单的pojo
我的uri是
http://localhost:8080/reportservice/reports?eaid=6764623946&source=ABC&userid=abhattacherji&org=trpo&startdate=8/11/2016&enddate=9/1/2016&page=1
我收到HTTP状态404错误。即使我忽略查询参数,第一部分(/ reportservice / reports)也不起作用。任何领导都会有所帮助。提前致谢。
答案 0 :(得分:0)
我认为你传递了错误的日期参数。
例如&startdate=8/11/2016
这可以被视为不同的路径变量。
您需要传递日期参数,例如
@DateTimeFormat(pattern =“MM / dd / yyyy”)其中yyyy是年份,MM是月份,dd是日期
public ResponseEntity<ResponseMessage> getReport(@DateTimeFormat(pattern="MM/dd/yyyy") Date startDate) {
...
}
有关详细信息,请点击此链接passing date into request param
答案 1 :(得分:0)
我做了三个改变并且有效: