4 changed files with 156 additions and 27 deletions
			
			
		- 
					43common/src/main/java/com/storeroom/base/BaseDTO.java
 - 
					78common/src/main/java/com/storeroom/base/BaseEntity.java
 - 
					35common/src/main/java/com/storeroom/base/BaseMapper.java
 - 
					27common/src/main/java/com/storeroom/exception/controller/TestController.java
 
@ -0,0 +1,43 @@ | 
				
			|||
package com.storeroom.base; | 
				
			|||
 | 
				
			|||
import lombok.Getter; | 
				
			|||
import lombok.Setter; | 
				
			|||
import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
import java.lang.reflect.Field; | 
				
			|||
import java.sql.Timestamp; | 
				
			|||
 | 
				
			|||
@Getter | 
				
			|||
@Setter | 
				
			|||
public class BaseDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    //创建人 | 
				
			|||
    private String createBy; | 
				
			|||
 | 
				
			|||
    //修改人 | 
				
			|||
    private String updateBy; | 
				
			|||
 | 
				
			|||
    //创建时间 | 
				
			|||
    private Timestamp createTime; | 
				
			|||
 | 
				
			|||
    //修改时间 | 
				
			|||
    private Timestamp updateTime; | 
				
			|||
 | 
				
			|||
    @Override | 
				
			|||
    public String toString() { | 
				
			|||
 | 
				
			|||
        ToStringBuilder builder = new ToStringBuilder(this); | 
				
			|||
 | 
				
			|||
        Field[] fields = this.getClass().getDeclaredFields(); | 
				
			|||
        try { | 
				
			|||
            for (Field f : fields) { | 
				
			|||
                f.setAccessible(true); | 
				
			|||
                builder.append(f.getName(), f.get(this)).append("\n"); | 
				
			|||
            } | 
				
			|||
        } catch (Exception e) { | 
				
			|||
            builder.append("toString builder encounter an error"); | 
				
			|||
        } | 
				
			|||
        return builder.toString(); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,78 @@ | 
				
			|||
package com.storeroom.base; | 
				
			|||
 | 
				
			|||
import com.alibaba.fastjson.annotation.JSONField; | 
				
			|||
import com.fasterxml.jackson.annotation.JsonProperty; | 
				
			|||
import io.swagger.annotations.ApiModelProperty; | 
				
			|||
import lombok.Getter; | 
				
			|||
import lombok.Setter; | 
				
			|||
import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			|||
import org.hibernate.annotations.CreationTimestamp; | 
				
			|||
import org.hibernate.annotations.UpdateTimestamp; | 
				
			|||
import org.springframework.data.annotation.CreatedBy; | 
				
			|||
import org.springframework.data.annotation.LastModifiedBy; | 
				
			|||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 
				
			|||
 | 
				
			|||
import javax.persistence.Column; | 
				
			|||
import javax.persistence.EntityListeners; | 
				
			|||
import javax.persistence.MappedSuperclass; | 
				
			|||
import java.io.Serializable; | 
				
			|||
import java.lang.reflect.Field; | 
				
			|||
import java.sql.Timestamp; | 
				
			|||
 | 
				
			|||
@Getter | 
				
			|||
@Setter | 
				
			|||
@MappedSuperclass | 
				
			|||
@EntityListeners(AuditingEntityListener.class) | 
				
			|||
public class BaseEntity implements Serializable { | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    @CreatedBy | 
				
			|||
    @Column(name = "create_by", updatable = false) | 
				
			|||
    @ApiModelProperty(value = "创建人", hidden = true) | 
				
			|||
    @JSONField(name="createBy") | 
				
			|||
    @JsonProperty("create_by") | 
				
			|||
    private String createBy; | 
				
			|||
 | 
				
			|||
    @LastModifiedBy | 
				
			|||
    @Column(name = "update_by") | 
				
			|||
    @ApiModelProperty(value = "更新人", hidden = true) | 
				
			|||
    @JSONField(name="updatedBy") | 
				
			|||
    @JsonProperty("update_by") | 
				
			|||
    private String updatedBy; | 
				
			|||
 | 
				
			|||
    @CreationTimestamp | 
				
			|||
    @Column(name = "create_time", updatable = false) | 
				
			|||
    @ApiModelProperty(value = "创建时间", hidden = true) | 
				
			|||
    @JSONField(name="createTime") | 
				
			|||
    @JsonProperty("create_time") | 
				
			|||
    private Timestamp createTime; | 
				
			|||
 | 
				
			|||
    @UpdateTimestamp | 
				
			|||
    @Column(name = "update_time") | 
				
			|||
    @ApiModelProperty(value = "更新时间", hidden = true) | 
				
			|||
    @JSONField(name="updateTime") | 
				
			|||
    @JsonProperty("update_time") | 
				
			|||
    private Timestamp updateTime; | 
				
			|||
 | 
				
			|||
    /* 分组校验 */ | 
				
			|||
    public @interface Create {} | 
				
			|||
 | 
				
			|||
    /* 分组校验 */ | 
				
			|||
    public @interface Update {} | 
				
			|||
 | 
				
			|||
    @Override | 
				
			|||
    public String toString() { | 
				
			|||
        ToStringBuilder builder = new ToStringBuilder(this); | 
				
			|||
 | 
				
			|||
        Field[] fields = this.getClass().getDeclaredFields(); | 
				
			|||
        try { | 
				
			|||
            for (Field f : fields) { | 
				
			|||
                f.setAccessible(true); | 
				
			|||
                builder.append(f.getName(), f.get(this)).append("\n"); | 
				
			|||
            } | 
				
			|||
        } catch (Exception e) { | 
				
			|||
            builder.append("toString builder encounter an error"); | 
				
			|||
        } | 
				
			|||
        return builder.toString(); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,35 @@ | 
				
			|||
package com.storeroom.base; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
public interface BaseMapper<D, E> { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * DTO转Entity | 
				
			|||
     * @param dto / | 
				
			|||
     * @return / | 
				
			|||
     */ | 
				
			|||
    E toEntity(D dto); | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Entity转DTO | 
				
			|||
     * @param entity / | 
				
			|||
     * @return / | 
				
			|||
     */ | 
				
			|||
    D toDto(E entity); | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * DTO集合转Entity集合 | 
				
			|||
     * @param dtoList / | 
				
			|||
     * @return / | 
				
			|||
     */ | 
				
			|||
    List<E> toEntity(List<D> dtoList); | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Entity集合转DTO集合 | 
				
			|||
     * @param entityList / | 
				
			|||
     * @return / | 
				
			|||
     */ | 
				
			|||
    List <D> toDto(List<E> entityList); | 
				
			|||
} | 
				
			|||
@ -1,27 +0,0 @@ | 
				
			|||
package com.storeroom.exception.controller; | 
				
			|||
 | 
				
			|||
import com.storeroom.exception.JsonException; | 
				
			|||
import com.storeroom.exception.PageException; | 
				
			|||
import com.storeroom.exception.constant.Status; | 
				
			|||
import com.storeroom.exception.handler.ApiResponse; | 
				
			|||
import org.springframework.stereotype.Controller; | 
				
			|||
import org.springframework.web.bind.annotation.GetMapping; | 
				
			|||
import org.springframework.web.bind.annotation.RequestBody; | 
				
			|||
import org.springframework.web.servlet.ModelAndView; | 
				
			|||
 | 
				
			|||
@Controller | 
				
			|||
public class TestController { | 
				
			|||
 | 
				
			|||
    @GetMapping | 
				
			|||
    public ApiResponse<Object> jsonException(){ | 
				
			|||
        throw new JsonException(Status.UNKNOWN_ERROR); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public ModelAndView pageException(){ | 
				
			|||
        throw new PageException(Status.UNKNOWN_ERROR); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
 | 
				
			|||
 | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue