Spring mvc 抛出 org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示

2023-12-22

我正在使用 springMVC,并且在尝试进行更新时遇到以下异常。

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 https://stackoverflow.com/questions/7197268/spring-mvc-httpmediatypenotacceptableexception在那里讨论了类似的问题,但我不确定如何用注释来解决这个问题。

任何想法?


由于控制器的返回值而引发异常。 一旦我更改了返回值,异常就消失了。

public @ResponseBody String updateJob(@RequestParam(value="job_id") String job_id){

我还将响应更改为空。

@RequestMapping(value="/updateJob", method=RequestMethod.GET)
public @ResponseBody String updateJob(@RequestParam(value="job_id") String job_id){
    Integer jobid = Integer.parseInt(job_id);

    JobQueue job = jobqueueService.getJob(jobid);
    .
    .
    return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring mvc 抛出 org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示 的相关文章

随机推荐