OpenFeign无法获取一个空对象

cwsong 发布于 2020/12/22 21:20
阅读 308
收藏 0
我尝试在用户模块的controller返回一个空对象(没有地址值的那种),然后在登录模块获取到这个对象的时候是有地址值的,但是这个对象字段都是null,在登录模块用 ObjectUtils.isEmpty(user) 来判断这个对象得出结果不为空,现在我想获取这个空对象该怎么获取?
AuthController:
@RestController
@RequestMapping( "/auth" )
public class AuthController{
    
    
    @Autowired
    private AuthService authService;
    
    @Autowired
    private UserService userService;    

    @PostMapping( "/regist/password" )
    public String regist( @RequestBody @Valid UserRegistByPasswordReqVo userRegistByPasswordReqVo ,
                          BindingResult result ){
        if( result.hasErrors() ) {
            throw new BusinessException( "-1" , Objects.requireNonNull( result.getFieldError() ).getDefaultMessage() );
        }
        User user = userService.findUser( userRegistByPasswordReqVo.getUsername() );
        Optional.ofNullable( user ).ifPresent( u -> {
            if( u.getId() != null ) {throw new AuthException( AuthErrorCode.ACCOUNT_EXIST_USERNAME );}
        } );
        
            userService.addUser( userRegistByPasswordReqVo );

        return "success";
    }
    
    
}

登录模块的UserService 接口:

@FeignClient( "demos-user" )
public interface UserService{
    
    
    @GetMapping( "/user/{username}" )
    User findUser( @PathVariable String username );
    
    @PostMapping("/user")
    void addUser(  UserRegistByPasswordReqVo userRegistByPasswordReqVo );
}

用户模块 UserController:

@RestController
@RequestMapping( "/user" )
public class UserController{
    
    @Autowired
    private UserService userService;

    
    @PostMapping
    public User addUser( @RequestBody UserRegistByPasswordReqVo userRegistByPasswordReqVoVo ){
        return userService.addUser( userRegistByPasswordReqVoVo );
    }
    
    @GetMapping( "/{username}" )
    public User findUser( @PathVariable String username ){
        User byUsername = userService.findByUsername( username );
        return userService.findByUsername( username );
    }
    

 关联问题(带图片):OpenFeign服务方返回null对象,调用方得到的却是一个具体对象,但是字段为null

加载中
0
c
cwsong
该评论暂时无法显示,详情咨询 QQ 群:点此入群
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部