pom
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.5.5.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</dependency>
案例1:
List<Island> islands = islandMapper.selectList(Wrappers.emptyWrapper());
List<IslandVO> islandList = IslandConvert.INSTANCE.convert(islands);
package com.zygh.data.manage.convert;
import com.zygh.data.manage.entity.Island;
import com.zygh.data.manage.vo.IslandVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @Description 岛对象转换类
* @Author wpz
* @Date 2023/10/25 19:38
*/
@Mapper
public interface IslandConvert {
IslandConvert INSTANCE = Mappers.getMapper(IslandConvert.class);
/**
* island 转 islandVO
*
* @param islands 岛集合
* @return islandVO
*/
@Mapping(target = "child", ignore = true)
List<IslandVO> convert(List<Island> islands);
}
package com.zygh.data.manage.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import java.util.List;
/**
* 岛信息表
*
* @author zygh
* @TableName dm_island
*/
@TableName(value = "dm_island")
@Data
@EqualsAndHashCode(callSuper = true)
public class Island extends Model<Island> {
/**
* id
*/
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "id", example = "1")
private Integer id;
/**
* 岛名
*/
@ApiModelProperty(value = "id", example = "桃花岛")
private String name;
/**
* 编号
*/
@ApiModelProperty(value = "编号", example = "NO1")
private String number;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间", example = "2023-09-20 08:43:47")
private Date gmtCreate;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间", example = "2023-09-20 08:43:47")
private Date gmtUpdate;
/**
* 分类集
*/
@TableField(exist = false)
@ApiModelProperty(hidden = true)
private List<MonitorClassification> child;
/**
* 新id 如:1-1
*/
@TableField(value = "id")
@ApiModelProperty(hidden = true)
private String uid;
/**
* 经度
*/
@ApiModelProperty(value = "经度", example = "112.88236411966768")
private String longitude;
/**
* 维度
*/
@ApiModelProperty(value = "维度", example = "9.546758089029431")
private String latitude;
/**
* 模型名称
*/
@ApiModelProperty(value = "模型名称", example = "ABV")
private String modelName;
/**
* 模型地址
*/
@ApiModelProperty(value = "模型地址", example = "地址1")
private String modelAddress;
/**
* 高度
*/
@ApiModelProperty(value = "高度", example = "8000")
private String height;
/**
* 相机位置
*/
@ApiModelProperty(value = "相机位置", example = "123")
private String cameraPosition;
}
package com.zygh.data.manage.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zygh.data.manage.entity.DataClassification;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @Description 岛屿VO
* @Author wpz
* @Date 2023/10/25 19:34
*/
@Data
@ApiModel("岛屿VO")
public class IslandVO {
/**
* id
*/
@ApiModelProperty(value = "id", example = "1")
private Integer id;
/**
* 岛名
*/
@ApiModelProperty(value = "岛名", example = "桃花岛")
private String name;
/**
* 编号
*/
@ApiModelProperty(value = "编号", example = "NO1")
private String number;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间", example = "2023-09-20 08:43:47")
private Date gmtCreate;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间", example = "2023-09-20 08:43:47")
private Date gmtUpdate;
/**
* 分类集
*/
@ApiModelProperty(value = "分类集")
private List<DataClassification> child;
/**
* 新id 如:1-1
*/
@ApiModelProperty(hidden = true)
private String uid;
}
案例2:
//获取字段信息
List<JobJdbcDatasourceManagerCloumn> jobJdbcDatasourceManagerCloumns = jobJdbcDatasourceManagerCloumnApi.tableId(id);
List<TableLabelVO> tableLabelVOList = TableConvert.INSTANCE.convert(jobJdbcDatasourceManagerCloumns);
package com.zygh.data.manage.convert;
import com.zygh.data.manage.vo.TableLabelVO;
import com.zygh.data_adapter_api.api.datasource.dto.JobJdbcDatasourceManagerCloumn;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @Description 表转换
* @Author wpz
* @Date 2023/10/30 17:28
*/
@Mapper
public interface TableConvert {
TableConvert INSTANCE = Mappers.getMapper(TableConvert.class);
/**
* 表转换
*
* @param jobJdbcDatasourceManagerCloumn 表信息
* @return 表转换
*/
@Mapping(source = "id", target = "fieldId")
@Mapping(source = "cloumnName", target = "fieldName")
TableLabelVO convert(JobJdbcDatasourceManagerCloumn jobJdbcDatasourceManagerCloumn);
/**
* 表list转换
*
* @param jobJdbcDatasourceManagerCloumns 表信息
* @return 表转换
*/
List<TableLabelVO> convert(List<JobJdbcDatasourceManagerCloumn> jobJdbcDatasourceManagerCloumns);
}
-
JobJdbcDatasourceManagerCloumn
package com.zygh.data_adapter_api.api.datasource.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 数据源下表字段信息表(JobJdbcDatasourceManagerCloumn)实体类
*
* @author makejava
* @since 2023-10-17 20:10:23
*/
@Data
@ApiModel("数据源下表字段信息表")
public class JobJdbcDatasourceManagerCloumn implements Serializable {
private static final long serialVersionUID = -57593056772585877L;
/**
* 主键id
*/
private Integer id;
/**
* 数据源表id
*/
private Integer jobJdbcDatasourceManagerId;
/**
* 字段名
*/
private String cloumnName;
/**
* 有效 无效 1有效 0无效
*/
private Integer status;
/**
* 逻辑删除 1 已删除0未删除
*/
private Integer deleted;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime gmtCreate;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime gmtUpdate;
/**
* 标识系统内部字段 还是其他系统表字段0是外部 1是内部 默认是0
*/
private Integer type;
/**
* 列类型
*/
private String cloumnType;
}
package com.zygh.data.manage.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Description 表与标签VO
* @Author wpz
* @Date 2023/10/30 15:21
*/
@Data
@ApiModel("表与标签VO")
public class TableLabelVO {
/**
* 字段id
*/
@ApiModelProperty(value = "字段id", example = "7")
private Integer fieldId;
/**
* 字段名
*/
@ApiModelProperty(value = "字段名", example = "field1")
private String fieldName;
/**
* 标签id
*/
@ApiModelProperty(value = "标签id", example = "7")
private Integer labelId;
/**
* 标签名
*/
@ApiModelProperty(value = "标签名", example = "label1")
private String labelName;
/**
* 分级;1-一般;2-内部;3-秘密
*/
@ApiModelProperty(value = "分级;1-一般;2-内部;3-秘密", example = "1")
private Integer grade;
/**
* 表id
*/
@ApiModelProperty(value = "表id", example = "1")
private Integer jobJdbcDatasourceManagerId;
}