- demo 项目,修改 rpc 层,出参为 dto
							parent
							
								
									2c7e1a97df
								
							
						
					
					
						commit
						9cadb9afd7
					
				| 
						 | 
				
			
			@ -4,6 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
 | 
			
		|||
import cn.iocoder.mall.demo.application.convert.DemoUserConvert;
 | 
			
		||||
import cn.iocoder.mall.demo.application.vo.DemoUserVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.api.DemoUserRpcService;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoUserDTO;
 | 
			
		||||
import org.apache.dubbo.config.annotation.Reference;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +21,7 @@ public class DemoUserController {
 | 
			
		|||
    // TODO 芋艿,这里只是做一个 demo 。实际一般不会这么玩,更多是内嵌的,像 {@link #get(Integer id)} 的情况。
 | 
			
		||||
    @GetMapping("/get")
 | 
			
		||||
    public CommonResult<DemoUserVO> get(@RequestParam("id") Integer id) {
 | 
			
		||||
        cn.iocoder.mall.demo.rpc.vo.DemoUserVO user = userRpcService.get(id);
 | 
			
		||||
        DemoUserDTO user = userRpcService.get(id);
 | 
			
		||||
        return CommonResult.success(DemoUserConvert.INSTANCE.convert(user));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package cn.iocoder.mall.demo.application.convert;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.mall.demo.application.vo.DemoUserVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoUserDTO;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
import org.mapstruct.Mappings;
 | 
			
		||||
import org.mapstruct.factory.Mappers;
 | 
			
		||||
| 
						 | 
				
			
			@ -11,6 +12,6 @@ public interface DemoUserConvert {
 | 
			
		|||
    DemoUserConvert INSTANCE = Mappers.getMapper(DemoUserConvert.class);
 | 
			
		||||
 | 
			
		||||
    @Mappings({})
 | 
			
		||||
    DemoUserVO convert(cn.iocoder.mall.demo.rpc.vo.DemoUserVO vo);
 | 
			
		||||
    DemoUserVO convert(DemoUserDTO vo);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.api;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoProductVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoProductDTO;
 | 
			
		||||
 | 
			
		||||
public interface DemoProductRpcService {
 | 
			
		||||
 | 
			
		||||
    DemoProductVO get(Integer id);
 | 
			
		||||
    DemoProductDTO get(Integer id);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.api;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoUserVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoUserDTO;
 | 
			
		||||
 | 
			
		||||
public interface DemoUserRpcService {
 | 
			
		||||
 | 
			
		||||
    DemoUserVO get(Integer id);
 | 
			
		||||
    DemoUserDTO get(Integer id);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,12 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.vo;
 | 
			
		||||
package cn.iocoder.mall.demo.rpc.dto;
 | 
			
		||||
 | 
			
		||||
import io.swagger.annotations.ApiModel;
 | 
			
		||||
import io.swagger.annotations.ApiModelProperty;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
@ApiModel("Demo 商品 BO")
 | 
			
		||||
@ApiModel("Demo 商品 DTO")
 | 
			
		||||
@Data
 | 
			
		||||
public class DemoProductVO {
 | 
			
		||||
public class DemoProductDTO {
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty(value = "编号", required = true, example = "1")
 | 
			
		||||
    private Integer id;
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.vo;
 | 
			
		||||
package cn.iocoder.mall.demo.rpc.dto;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.experimental.Accessors;
 | 
			
		||||
 | 
			
		||||
@Data
 | 
			
		||||
@Accessors(chain = true)
 | 
			
		||||
public class DemoUserVO {
 | 
			
		||||
public class DemoUserDTO {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户编号
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.convert;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoProductVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoProductDTO;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
import org.mapstruct.Mappings;
 | 
			
		||||
import org.mapstruct.factory.Mappers;
 | 
			
		||||
| 
						 | 
				
			
			@ -12,6 +12,6 @@ public interface DemoProductConvert {
 | 
			
		|||
    DemoProductConvert INSTANCE = Mappers.getMapper(DemoProductConvert.class);
 | 
			
		||||
 | 
			
		||||
    @Mappings({})
 | 
			
		||||
    DemoProductVO convert(DemoProductBO object);
 | 
			
		||||
    DemoProductDTO convert(DemoProductBO object);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
package cn.iocoder.mall.demo.rpc.convert;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.mall.demo.business.bo.user.DemoUserBO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoUserVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoUserDTO;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
import org.mapstruct.Mappings;
 | 
			
		||||
import org.mapstruct.factory.Mappers;
 | 
			
		||||
| 
						 | 
				
			
			@ -12,6 +12,6 @@ public interface DemoUserConvert {
 | 
			
		|||
    DemoUserConvert INSTANCE = Mappers.getMapper(DemoUserConvert.class);
 | 
			
		||||
 | 
			
		||||
    @Mappings({})
 | 
			
		||||
    DemoUserVO convert(DemoUserBO object);
 | 
			
		||||
    DemoUserDTO convert(DemoUserBO object);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ import cn.iocoder.mall.demo.business.api.DemoProductService;
 | 
			
		|||
import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.api.DemoProductRpcService;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.convert.DemoProductConvert;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoProductVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoProductDTO;
 | 
			
		||||
import org.apache.dubbo.config.annotation.Service;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ public class DemoProductRpcServiceImpl implements DemoProductRpcService {
 | 
			
		|||
    private DemoProductService productService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public DemoProductVO get(Integer id) {
 | 
			
		||||
    public DemoProductDTO get(Integer id) {
 | 
			
		||||
        DemoProductBO product = productService.get(id);
 | 
			
		||||
        return DemoProductConvert.INSTANCE.convert(product);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ import cn.iocoder.mall.demo.business.api.DemoUserService;
 | 
			
		|||
import cn.iocoder.mall.demo.business.bo.user.DemoUserBO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.api.DemoUserRpcService;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.convert.DemoUserConvert;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.vo.DemoUserVO;
 | 
			
		||||
import cn.iocoder.mall.demo.rpc.dto.DemoUserDTO;
 | 
			
		||||
import org.apache.dubbo.config.annotation.Service;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ public class DemoUserRpcServiceImpl implements DemoUserRpcService {
 | 
			
		|||
    private DemoUserService demoUserService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public DemoUserVO get(Integer id) {
 | 
			
		||||
    public DemoUserDTO get(Integer id) {
 | 
			
		||||
        DemoUserBO userBO = demoUserService.get(id);
 | 
			
		||||
        return DemoUserConvert.INSTANCE.convert(userBO);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue