IntelliJ 创建Sharp DB模板(Entity/Enum/DAO/Service)

File Header

/**
 * @author Rick.Xu
 * @date ${DATE} ${TIME}
 */

QueryResult

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.rick.db.plugin.dao.annotation.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;

#parse("File Header.java")
@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
@Table
public class ${NAME} {

}

Entity

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.rick.db.dto.BaseEntity;
import com.rick.db.plugin.dao.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

#parse("File Header.java")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@SuperBuilder
@Table(value = "table_name", comment = "表描述")
public class ${NAME} extends BaseEntity {

}

EnumCode

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

#parse("File Header.java")
@AllArgsConstructor
@Getter
public enum ${NAME}Enum {
    NAME1(0, "NAME1"),
    NAME2(1, "NAME2");
    private static final Map<Integer, ${NAME}Enum> codeMap = new HashMap<>();
    static {
        for (${NAME}Enum e : values()) {
            codeMap.put(e.code, e);
        }
    }
    private final int code;
    private final String label;
    @JsonValue
    public int getCode() {
        return this.code;
    }

    /**
     * code枚举 必须重写toString()
     * @return
     */
    @Override
    public String toString() {
        return String.valueOf(code);
    }

    public static ${NAME}Enum valueOfCode(int code) {
        return codeMap.get(code);
    }
}

EnumCode2

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

#parse("File Header.java")
@AllArgsConstructor
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ${NAME}Enum {
    NAME1(0, "NAME1"),
    NAME2(1, "NAME2");
    private static final Map<Integer, ${NAME}Enum> codeMap = new HashMap<>();
    static {
        for (${NAME}Enum e : values()) {
            codeMap.put(e.code, e);
        }
    }
    private final int code;
    private final String label;

    public int getCode() {
        return this.code;
    }

    /**
     * code枚举 必须重写toString()
     * @return
     */
    @Override
    public String toString() {
        return String.valueOf(code);
    }

    public static ${NAME}Enum valueOfCode(int code) {
        return codeMap.get(code);
    }
}

EnumName

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

#parse("File Header.java")
@AllArgsConstructor
@Getter
public enum ${NAME}Enum {
    NAME1("NAME1"),
    NAME2("NAME2");

    @JsonValue
    public String getCode() {
        return this.name();
    }
    private final String label;
    public static ${NAME}Enum valueOfCode(String code) {
        return valueOf(code);
    }
}

EnumName2

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;

#parse("File Header.java")
@AllArgsConstructor
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ${NAME}Enum {
    NAME1("NAME1"),
    NAME2("NAME2");

    public String getCode() {
        return this.name();
    }
    private final String label;
    public static ${NAME}Enum valueOfCode(String code) {
        return valueOf(code);
    }
}

DAO

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")#set($folderIndex = $PACKAGE_NAME.length() - 4)#end

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.rick.db.plugin.dao.core.EntityDAOImpl;
import #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")${PACKAGE_NAME.substring(0, $folderIndex)}.entity.#end${NAME};
import org.springframework.stereotype.Repository;

#parse("File Header.java")
@Repository
public class ${NAME}DAO extends EntityDAOImpl<${NAME}, Long> {

}

Service

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")#set($folderIndex = $PACKAGE_NAME.length() - 8)#end
#set($length = $NAME.length())

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")${PACKAGE_NAME.substring(0, $folderIndex)}.dao.#end${NAME}DAO;
import lombok.RequiredArgsConstructor;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

#parse("File Header.java")
@Service
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
@Validated
public class ${NAME}Service {
    ${NAME}DAO ${NAME.substring(0,1).toLowerCase()}${NAME.substring(1,$length)}DAO;
}