1

この問題の背景。フロント エンドから、複数のプロパティを持つ 2 つの選択ボックスがあります。1 つのボックスは承認されたアイテム用で、もう 1 つのボックスは無視されたアイテム用です。これらをマップに配置し、キーは会社の UID であり、値は UID がどのボックスにあるかに応じて「Y」または「N」になります。ibatis を使用して HashMap 値をテーブルに挿入すると、いくつかの助けが得られましたが、答えはエントリを手動で配置する必要がありましたが、マップを動的に作成しているため、キーがどうなるかわかりません。以下は Java のコードです。

// Set up the map object for the back end
        Map<Integer, String> posMap = new HashMap<Integer, String>();
        // Get the approved mailers
        String[] mailerList = request.getParameterValues("approved");                   
        if (mailerList != null && mailerList.length > 0)
        {
            for(String mailer : mailerList)
            {
                posMap.put(Integer.parseInt(mailer), "Y");
            }
        }
        // reset the mailerList
        mailerList = null;
        // get the ignored mailers
        mailerList = request.getParameterValues("ignored");
        if (mailerList != null && mailerList.length > 0)
        {
            for(String mailer : mailerList)
            {
                posSampleMap.put(Integer.parseInt(mailer), "N");
            }
        }
        // only update POS if the map is not empty
        if(!posMap.isEmpty())
        {               
            updateMapper.updatePOSSampling(posMap);
        }

通常、mapper.xml ファイルには次のようなものがあります。

<update id="updatePOSSampling" parameterType="hashmap">
   UPDATE <table_name>
   SET sampling_enabled = ${myMapValue}
   WHERE mailer_name = ${myMapKey}
</update>

私が提供したリンクでは、彼らは手動でキーと値を入力していたため、IBATIS の例はキーを参照できました。私のキーが何かわからないので、このクエリを生成する最良の方法は何ですか? 2 次元配列を送信する一時的な回避策がありますが、Map DO を使用する方が良い方法だと思います。ご協力いただきありがとうございます。

4

0 に答える 0