我的课程相同:
public class Person{
private String id =null;
private String type =null;
public Person(){
}
set and get methods.....
}
现在我有了Spring MVC的RESTFULL应用程序,控制器是:
@Controller
public class RestProviderController extends Thread {
@Autowired
BundleContext bundleContext;
protected static Logger logger = Logger.getLogger("controller");
protected static boolean status=false;
@Resource(name="Service")
private ElementService service;
public RestProviderController(){
}
@RequestMapping(value = "/person/{id}", method = RequestMethod.GET, headers="Accept=application/xml, application/html")
public @ResponseBody ResponseEntity<Response> Query(@PathVariable("id") String id) {
RestPerson response = service.queryContext(id);
return new ResponseEntity<Response>(response, HttpStatus.OK);
}
return null;
}
问题是:当我调用方法service.queryContext(id)时,返回Person类的istance,我想将这个对象映射到另一个Person类“RestPerson”。这个RestPerson类等于Person,但在Person类中我添加了一些mvcannotation来转换XML中的响应。 RestPerson是:
@XmlRootElement(name="Person")
@XmlAccessorType(XmlAccessType.FIELD)
public class Person{
private String id =null;
private String type =null;
public Person(){
}
set and get methods.....
}
问题是转换是不允许的,因为jvm不知道Person和RestPerson是等于的。怎么能解决这个问题?因为我不想手动转换所有信息。