环境: spring boot 1.5.9+ feign+eurakespring
客户端代码:app
@Component @FeignClient("pubcloud-system") public interface PointInterface { @PostMapping("/s/point/handlePointEvent") ResultInfo handlePointEvent(@RequestBody ObjectEvent event); }
服务端代码post
@RestController @RequestMapping("/s/point") public class PointServiceController { @Autowired private PointHandler pointHandler; @Autowired private PlatformUserPointService platformUserPointService; @PostMapping("/handlePointEvent") public ResultInfo handlePoint(@RequestBody ObjectEvent pointSupport) throws Exception { pointHandler.handle(pointSupport); return new ResultInfo(ResultCodeEnum.success); } }
ObjectEvent 类数据以下this
public class ObjectEvent extends ApplicationEvent implements PointSupport { private String activeCode; private String ObjectId; private String userId; private long pointNum; private String activeDescription; private String activeId; private String platformCode; public ObjectEvent(Object source, String activeCode, String objectId, String userId, String activeDescription) { super(source); this.activeCode = activeCode; ObjectId = objectId; this.userId = userId; this.activeDescription = activeDescription; } public ObjectEvent(Object source, String activeCode, String objectId, String userId, String activeDescription, String activeId, String platformCode) { super(source); this.activeCode = activeCode; ObjectId = objectId; this.userId = userId; this.activeDescription = activeDescription; this.activeId = activeId; this.platformCode = platformCode; } //略去get,set方法 }
调用时,发现pointNum的值老是为0;而后就进行了排除;debug
这样结果已肯定,fastJson调用了一个非默认的构造器来实例化,那么其余的属性就不会再set了.添加了一个无参默认构造器,pointNum的值就能够正确传递了和接受了code