亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Azure 插入不添加實體的新屬性 (Java)

Azure 插入不添加實體的新屬性 (Java)

牛魔王的故事 2021-11-11 15:36:34
我有一個帶有 Azure 表存儲的數據庫,我在其中存儲具有各種屬性的實體,并且一切運行良好。但是,當我嘗試添加新屬性時,它根本沒有被存儲。我的 InsertEntity 代碼如下所示:LunchDateEntity entity = new LunchDateEntity(ID);try{AppStorage storage = new AppStorage(TABLENAME);entity.setProperty1(prop1)entity.setProperty2(prop2)entity.setProperty3(prop3)entity.setNewProperty(newProp)TableOperation operation = TableOperation.insert(entity);m_table.execute(operation);} catch(...) {...}Prop 1,2,3 是我以前擁有的實體,它們被添加到表存儲中,但是,newProp 根本沒有在表存儲中顯示。我嘗試在構建實體時對該屬性進行硬編碼,但無濟于事。我的實體類看起來像:public class myEntity extends TableServiceEntity {public static final String TABLENAME = "myTable";public static final String PARTITION_KEY = "part1";public String m_prop1 = "";public String m_prop2 = "";public String m_prop3 = "";public String m_newProp = "";public myEntity() { this.partitionKey = PARTITION_KEY;} public void setProp1(String prop1) {  m_prop1 = prop1;}public String getProp1() { return m_prop1;}public void setNewProp(String newProp) { m_newProp = newProp;}對于所有屬性,依此類推。他們都長得很像。我是否誤解了插入功能的工作原理?有什么想法為什么這不起作用?提前致謝
查看完整描述

1 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

根據我的測試,我認為這是因為名稱規則。我測試了添加 newProp 或 newProp1 字段,與您的解決方案相同。新房沒有出現。


然后我嘗試添加姓名、電話或什至 oldProp,一切正常。


功能代碼:


@FunctionName("addentity")

    public String addentity(@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) String req,

                            ExecutionContext context) {


        String storageConnectionString =

                "***";

        String jsonStr = "insert failed";


        try {

            // Retrieve storage account from connection-string.

            CloudStorageAccount storageAccount =

                    CloudStorageAccount.parse(storageConnectionString);


            // Create the table client.

            CloudTableClient tableClient =

                    storageAccount.createCloudTableClient();


            // Create a cloud table object for the table.

            CloudTable cloudTable = tableClient.getTableReference("test");


            // Create a new customer entity.

            myEntity entity = new myEntity("jay1","gong");

            //entity.setProp1("a");

            entity.setNewProp("new");

            entity.setOldProp("old");

            //entity.setNewProp1("new1");

            //entity.setName("kkkkk");


            // Create an operation to add the new customer to the people table.

            TableOperation insertEntity =

                    TableOperation.insert(entity);


            // Submit the operation to the table service.

            cloudTable.execute(insertEntity);


            jsonStr = entity.toString();


        } catch (Exception e) {

            // Output the stack trace.

            e.printStackTrace();

        }



        return jsonStr;

    }

我的實體:


package com.fabrikam.functions;


import com.microsoft.azure.storage.table.TableServiceEntity;


public class myEntity extends TableServiceEntity {


    public String m_prop1 = "";

    public String m_newProp = "";

    public String m_newProp1 = "";


    public String name = "";

    public String oldProp = "";


    public myEntity(String lastName, String firstName) {

        this.partitionKey = lastName;

        this.rowKey = firstName;

    }


    public void setProp1(String prop1) {

        m_prop1 = prop1;

    }


    public String getProp1() {

        return m_prop1;

    }



    public String getNewProp(String newProp) {

        return m_newProp;

    }


    public String getNewProp1(String newProp1) {

        return m_newProp1;

    }



    public void setNewProp(String newProp) {

        m_newProp = newProp;

    }


    public void setNewProp1(String newProp1) {

        m_newProp1 = newProp1;

    }


    public String getName() {

        return name;

    }


    public void setName(String name) {

        this.name = name;

    }


    public String getOldProp() {

        return oldProp;

    }


    public void setOldProp(String oldProp) {

        this.oldProp = oldProp;

    }

}

輸出:

http://img1.sycdn.imooc.com//618cc8250001eb9810880435.jpg

我認為'newProp'Azure 表存儲保留了類似的內容,您可以調整名稱規則,然后一切都會好起來的。


我做進一步的測試:

http://img1.sycdn.imooc.com//618cc8330001b97d10950309.jpg

只是為了總結,最后,這完全是關于我的 getter 和 setter 的錯誤格式。我們需要檢查對象定義。


查看完整回答
反對 回復 2021-11-11
  • 1 回答
  • 0 關注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號