1.1.
Update
updates that are logged by using the UPDATE statement.
Maper Configuration:
<!---<id= "Updateperson" parametertype = "Com.test.mybatis3.pojo.Person">update t_person set Name=#{name},status=#{status} Where Id=#{id}</update>
Mapper interface Method:
/**@param person @throws */void Throws
Unit Test Code:
New Person ();p Erson.setid ("Zhangsan");p erson.setname ("New Zhangsan");p Erson.setstatus (3 );p Ersonmapper.updateperson (person); Session.commit ();
Operation Result:
0 [main] DEBUG Com.test.mybatis3.mapper.PersonMapper.updatePerson-==> preparing:update T_person set Name=?,stat Us=? where id=?
[Main] DEBUG Com.test.mybatis3.mapper.PersonMapper.updatePerson-==> parameters:new Zhangsan (String), 3 (Integer ), Zhangsan (String)
Bayi [main] DEBUG Com.test.mybatis3.mapper.PersonMapper.updatePerson-<== updates:1
SQL Query:
Results before the update:
Mysql> select * from T_person;
+----------+-----------+--------+
| ID | name | Status |
+----------+-----------+--------+
| Lisi | Li Si | 0 |
| Zhangsan | Zhang San | 0 |
+----------+-----------+--------+
2 rows in Set (0.00 sec)
Results after the update:
Mysql> SELECT * from T_person where id= ' Zhangsan ';
+----------+--------------+--------+
| ID | name | Status |
+----------+--------------+--------+
| Zhangsan | New Zhangsan | 3 |
+----------+--------------+--------+
1 row in Set (0.00 sec)
The update statement can use the Selectkey statement to set or query the new primary key, using the Selectkey in the insert statement Same, no longer repeat.
MyBatis application Development (21) using Update nodes to express database record updates