MyBatis application Development (21) using Update nodes to express database record updates

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.