標籤:char bin update each 12c add entity time exist
1,mybatis中操作注意點
1,update語句與insert語句傳回值是語句影響資料庫的行數,而不是成功執行就返回1,
Dog dag = new Dog("a");
//插入一個對象執行成功返回1Integer affectNo = daoImpl.insert(dog);List dogs = new ArrayList<Dog>();dogs.add(new Dog("b"));dogs.add(new Dog("c"))
//更新兩個對象的資訊,執行成功後,返回2Integer affectNo =daoImpl.update(dogs);
2, 同一個事務的操作中,前面方法對資料庫進行的寫操作,會改變事務內資料庫的資料,能夠在下一個方法的查詢方法中被查詢到。
3, 實體類(entity)對象的屬性 < 資料庫的欄位時 => 不會報錯
實體類(entity)對象的屬性 > 資料庫的欄位時 => 會報錯
4, 資料表對應的entity 的類,必須有無參的構造方法,不然sql語句會報錯
2,插入資料時,返回自增主鍵id
<!-- 插入賬戶表情況,useGeneratedKeys="true" keyProperty="id"-->
<insert id="insert" parameterType="map" useGeneratedKeys="true" keyProperty="id"> INSERT INTO account (`account_id`, `total_point`) VALUES (#{accountId}, #{totalPoint}) </insert>
//主鍵是自增策略的情況下,設定每插入一條資料,返回資料的ID<insert id="insert" parameterType="com.2412cyy.pojo.TbContentCategory" > <selectKey keyProperty="id" resultType="long" order="AFTER"> select LAST_INSERT_ID()//取到最後產生的主鍵 </selectKey> insert into tb_content_category (id, parent_id, name, status, sort_order, is_parent, created, updated) values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{sortOrder,jdbcType=INTEGER}, #{isParent,jdbcType=BIT}, #{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP}) </insert>3,動態拼接sql語句
//List參數在mybatis中的拼接方法(idList是傳入的list型別參數)<if test="idList != null"> AND opr.order_id IN <foreach item="item" index="index" collection="idList" open="(" separator="," close=")"> #{item} </foreach> </if>4,exists函數的用法
<if test="isReceive == 1">AND NOT EXISTS (select 1 FROM order_xxx WHERE order_xx=opr.id AND is_receive=1)</if>
5,mysql建立新使用者並授權相關表
Mysql 本地的安裝路徑:
/usr/local/mysql/bin/mysql -u root -p
建立新使用者
create user admin identified by ‘admin‘;
授權:
grant all on db32.* to admin;
mybatis返回自增主鍵的id,動態拼接查詢語句,mysql建立新使用者並授權相關表