js obj 生成java 实体 entity

js obj 生成java 实体 entity

D:\proj\js\js-util\gen_java.js

文档:js obj 生成java 实体 entity.note
链接:http://note.youdao.com/noteshare?id=c61fbd4b8684dc41c8c9ab42107d5f87&sub=E7484F5F277041578A2E58FDC6320BA6
添加链接描述

class Shop{
    constructor(shopInfo){
        this.logo = shopInfo.shopLogo;
        this.name = shopInfo.name;
        this.fans = shopInfo.cFans;
        this.sells = shopInfo.cSells;
        this.score = shopInfo.score;
        this.goodsCount = shopInfo.cGoods;
    }
}

let commentInfo={
    user:{
        avatar:"",
        uname:""
    },
    content:"",
    created:"",
    style:"",
    images:[]
}

console.log("commentInfo");
console.log(commentInfo);

function getConversationID(){
    return null
}

function getUserID(){
    return null
}

 shop= {
    "model": "openbuddy-13b-v1.3-fp16",
    "messages": [
      {
        "role": "user",
        "content": "test"
      }
    ],
    "temperature": 0.5,
    "max_new_tokens": 700,
    "conversation_id": getConversationID(),
    "user_id": getUserID()
  }
  

let java_fields=""

function title(str){
    // a = a[0].toUpperCase() + a.substr(1)  
    return        str[0].toUpperCase() + str.substr(1)  
}


function strIsIn(smallStr,bigStr){
    return bigStr.includes(smallStr)
}

function getTypeName(field){
    // let typeName="String"
    if ( strIsIn("id",field) ){
        // typeName="Integer"
        return "Integer"
    }
    return "String"
}
// 这个可以
for (const field in shop) {
    console.log("field");
    console.log(field);
    // title
    // js title 
    let  fieldClsName= title(field)

    let typeName=   getTypeName(field)

    java_fields+= ` public   ${typeName} ${field}= "${field}";\n`

    // java_fields+=`String ${field};\n`
    //  let val=shop[field]
}
console.log("java_fields");
console.log(java_fields);
console.log(shop);

let classStr=`
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class ${Shop.name} {
    ${java_fields}
}`

console.log("\n\n\n\n\n\n");
console.log(classStr);

你可能感兴趣的:(javascript,java,开发语言)