繁体   English   中英

抽象类@RestController Spring 4 - @ResponseBody错误

[英]Abstract class @RestController Spring 4 - @ResponseBody error

我正在对我的CRUD进行抽象,使用我需要的方法创建一个抽象类。 尽管已经完成了,但是当我发送插入请求(POST)和更新(PUT)时,Spring框架没有将<@RequestBody T>转换为具体的类。 任何调用“createdAction”或“updateAction”的方法都不起作用。

@RestController
@RequestMapping("/user")
public class UserWebResource extends AbstractWebResource<UserEntity> { }

__

public abstract class AbstractWebResource<T extends PersistenceEntity> {

     @RequestMapping(method = RequestMethod.POST, produces = "application/json")
     public ResponseEntity<T> createAction(@RequestBody T dataEntity, HttpSession session) {
        dataEntity = rule.save(dataEntity);

        if (dataEntity.hasErrors()) {
           return new ResponseEntity<T>(dataEntity, HttpStatus.BAD_REQUEST);
        }

        return new ResponseEntity<T>(dataEntity, HttpStatus.CREATED);
     }

     @RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = "application/json")
     public ResponseEntity<T> updateAction(@PathVariable("id") Integer id, @RequestBody T dataEntity, HttpSession session) { ... }
}

POST e PUT出错

严重:路径为[/ app]的Servlet [dispatcher]的Servlet.service()抛出异常[请求处理失败; 嵌套异常是java.lang.IllegalStateException:参数类型不匹配HandlerMethod详细信息:Controller [br.inf ... web.resource.UserWebResource] 方法[public org.springframework.http.ResponseEntity br.inf ... web.resource.AbstractWebResource .updateAction(java.lang.String中,T,的javax.servlet.http.HttpSession)]

似乎封送处理框架存在问题。

您不能在Jackson 2.7和Spring 4.2中使用泛型类型,您应该将Jackson依赖版本回滚到2.6.6或使用Spring 4.3(当它出来时)。

资源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM