1,mybatis in the operation note Point
The return value of the 1,update statement and the INSERT statement is the number of rows that the statement affects the database, rather than a successful execution that returns 1.
Dog dag = new Dog ("a");
Insert an object to perform a successful return 1Integer Affectno = Daoimpl.insert (dog); List dogs = new arraylist<dog> ();d Ogs.add (New Dog ("B"));d Ogs.add (New Dog ("C"))
Updated information for two objects, after successful execution, return 2Integer Affectno =daoimpl.update (dogs);
2, in the operation of the same transaction, the previous method writes to the database, changes the data of the database within the transaction, and can be queried in the query method of the next method.
3, property of entity Class (entities) object < database field when = = does not error
Attribute > Database fields for entity class (entities) object = Error
4, the data table corresponding to the entity class, must have an argument-free construction method, otherwise the SQL statement will error
2, when inserting data, return the self-increment primary key ID
<insert id= "Insert" parametertype= "map" usegeneratedkeys= "true" keyproperty= "id" > INSERT into account (' Account_ Id ', ' total_point ') VALUES (#{accountid}, #{totalpoint}) </insert>
If the primary key is a self-increment policy, set the Id<insert id= "Insert" parametertype= "com.2412cyy.pojo.tbcontentcategory" for each insert of data that is returned to the data > <selectkey keyproperty= "id" resulttype= "long" order= "after" > select last_insert_id ()//take to the last generated primary key </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, dynamic splicing SQL statement
The concatenation method of the list parameter in MyBatis (Idlist is the incoming list type parameter) <if test= "Idlist! = null" > and opr.order_id in < foreach item= "item" index= "index" collection= "Idlist" open= "(" separator= "," close= ")" > #{item} </ Foreach> </if>
The use of the 4,exists function
<if test= "isreceive = = 1" >and not EXISTS (select 1 from order_xxx WHERE order_xx=opr.id and is_receive=1) </if>
5,mysql creating new users and authorizing related tables
Mysql Local Installation path:
/usr/local/mysql/bin/mysql-u root-p
Create a new user
Create user admin identified by ' admin ';
Authorized:
Grant all on db32.* to admin;
MyBatis returns the ID of the self-increment primary key, dynamically stitching the query statement, MySQL creates a new user and authorizes the related table