All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bak.struct.btl Maven / Gradle / Ivy

The newest version!
package ${packageName}.structs;

import lombok.Data;
import java.util.Map;
import cn.hutool.core.map.MapUtil;
import ${packageName}.StructUtil;
<%
	var extends = false;
	var extendConstant = "";
	if(strutil.isNotBlank(struct.extendsName)){
		extends = true;
		extendConstant = "extends " + struct.extendsName;
	}else{
		extends = false;
		extendConstant = "implements DTO";
	}
%>
<%if(!extends){%>
import org.artifact.core.lang.DTO;
<%}%>
@Data
/**
 * ${struct.remark}
 */
public class ${struct.structName} ${extendConstant}{
	<%for(field in struct.fields){%>
	/** ${field.key.remark} */
	<%if(strutil.startWith(field.value.type,"java.util.Map")){%>
	private ${field.value.intact} ${field.key.name} = new java.util.HashMap<>();
	<%}else if(strutil.startWith(field.value.type,"java.util.List")){%>
	private ${field.value.intact} ${field.key.name} = new java.util.ArrayList<>();
	<%}else{%>
	private ${field.value.intact} ${field.key.name};
	<%}%>
	<%}%>

	public Map toMap(Map map){
		<%if(extends){%>
		super.toMap(map);
		<%}%>
		<%
		var hashArray = [];
		for(field in struct.fields){
		hashCode = HashUtil.javaDefaultHash(field.key.name)+"";
		if(array.contain(hashArray,hashCode)){
			println("		"+field.key.name+":HashCode重复,请重命名");
			continue;
		}else{
			array.add(hashArray,hashCode);
		}
		%>
		map.put(${hashCode},StructUtil.tryEncoder(this.${field.key.name}));
	    <%}%>
	    return map;
	}

	public ${struct.structName} forMap(Map map){
        <%if(extends){%>
        super.forMap(map);
        <%}%>
        <%
        for(field in struct.fields){
        hashCode = HashUtil.javaDefaultHash(field.key.name)+"";
        %>
        this.${field.key.name} = StructUtil.tryDecoder(map.get(${hashCode}));
        <%}%>
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy