標籤:str result sep value batch values 實體類 als val
vlist提取欄位產生新list
List<int> uidList = urResult.stream().map(p -> p.getUserId()).collect(Collectors.toList());
vList中根據某個欄位條件產生新list
List<User> temp = uList.stream().filter(item -> item.getUid() == 10000).collect(Collectors.toList());
v去除List合格元素
Optional<Ticket> oTicket = topicList.stream().filter(p -> p.getId().equals(to.getId())).findFirst(); if (oTopic.isPresent()) { Ticket tempTicket = oTicket.get(); }vMybatis批量修改
<update id="updateBatch" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update course <set> name=${item.name} </set> where id = ${item.id} </foreach> </update>vMybatis實現InsertOrUpdate
<insert id="saveOrUpdate" > <selectKey keyProperty="count" resultType="int" order="BEFORE"> select count(*) from country where id = #{id} </selectKey> <if test="count > 0"> update country set countryname = #{countryname},countrycode = #{countrycode} where id = #{id} </if> <if test="count==0"> insert into country values(#{id},#{countryname},#{countrycode}) </if></insert>
條件限制
根據不同的判斷邏輯,會有所不同,就上面這個例子而言,就要求實體類中包含count屬性(可以是別的名字)。否則selectKey的結果沒法儲存,如果入參是個Map類型,就沒有這個限制。
說明
從例子來看除了有個限制外,也沒別的麻煩。
通過selectKey做第一次查詢,然後根據結果進行判斷,所以這裡的order="BEFORE"是必須的。
也是因為BEFORE,所以沒法通過<bind>標籤來臨時儲存中間的值,只能在入參中增加屬性來存放。
v非同步線程Thread
new Thread(){ public void run() { // 方法體 } }.start();vJava計算代碼執行時間
long startTime = System.currentTimeMillis();long endTime = System.currentTimeMillis();float seconds = (endTime - startTime) / 1000F;System.out.println("Cost seconds" + Float.toString(seconds));
Java 技術筆記