用maven引入jackson-databind包
<!-- http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.3</version>
</dependency>
调用com.fasterxml.jackson.databind包下的ObjectMapper类中的convertValue方法。例:
public Object toBody(Object param) {
//ObjectMapper实例
ObjectMapper objectMapper=new ObjectMapper();
//转化为实体类PartnerRegisterBo
PartnerRegisterBo bo = objectMapper.convertValue(param, PartnerRegisterBo.class);
return bo;
}
你适合学Java吗?4大专业测评方法
代码逻辑 吸收能力 技术学习能力 综合素质
先测评确定适合在学习