我正在使用springMVC,並且在嘗試執行更新時出現以下異常。Spring mvc拋出org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示
10:10:49,847 DEBUG LogicalConnectionImpl:250 - Released JDBC connection
10:10:49,859 DEBUG FixedContentNegotiationStrategy:48 - Requested media types is text/html (based on default MediaType)
10:10:49,929 DEBUG ExceptionHandlerExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
10:10:49,937 DEBUG ResponseStatusExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
10:10:49,938 DEBUG DefaultHandlerExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
10:10:49,940 DEBUG DispatcherServlet:999 - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
10:10:49,940 DEBUG DispatcherServlet:966 - Successfully completed request
10:10:49,941 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
以下是引發異常的控制器方法。我需要做些什麼來完成這項工作?
@RequestMapping(value="/updateJob", method=RequestMethod.GET)
public @ResponseBody JobQueue updateJob(@RequestParam(value="job_id") String job_id, @RequestParam String test_id, @RequestParam(value="status") String status) {
JobQueue job = jobqueueService.getJob(Integer.parseInt(job_id));
job.setTest_id(test_id);
job.setStatus(Integer.parseInt(status));
jobqueueService.updateJob(job);
return job;
}
我發現下面的帖子Spring MVC - HttpMediaTypeNotAcceptableException這裏討論類似的問題,但我不知道如何去用註解解決這個。
任何想法?
但是小它是。永遠不要說這是一個寶貴的問題,寶貴的答案。我在某個地方是正確的,我只是忘了它。這幫助我迅速找到自己的錯誤。所以不要忽視這個問題。謝謝!! –
@ user1647708:那麼如果我的退貨類型是列表?我應該返回什麼? –