我正在一个Spring Rest项目中,我想使用@MatrixVariable
。
不幸的是,我没有找到如何像使用@RequestBody
一样使用Jackson来将MatrixVariable自动转换为POJO的方法...
我的代码如下(以EmployeeSkillId作为复合ID):
@DeleteMapping("/employee-skills/{id}")
@Timed
public ResponseEntity<Void> deleteEmployeeSkill(@MatrixVariable(pathVar = "id") Map<String, String> id) {
//TODO fix this so that serialization is done automatically
final ObjectMapper mapper = new ObjectMapper(); // jackson's objectmapper
final EmployeeSkillId employeeSkillId = mapper.convertValue(id, EmployeeSkillId.class);
log.debug("REST request to get EmployeeSkill : {}", id);
employeeSkillService.delete(employeeSkillId);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
}
我更喜欢这样:
@DeleteMapping("/employee-skills/{id}")
@Timed
public ResponseEntity<Void> deleteEmployeeSkill(@MatrixVariable(pathVar = "id") EmployeeSkillId employeeSkillId) {
log.debug("REST request to get EmployeeSkill : {}", employeeSkillId);
employeeSkillService.delete(employeeSkillId);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
}
有关如何执行此操作的任何想法。
谢谢