05_ Updating data

Source: Internet
Author: User

"User.xml"

<!--           Update User         Analysis:         requires an incoming user's ID         to require an incoming user's update information         parametertype Specify the user object, including the ID and update information, note that the ID must exist         #{id} : Get     id attribute value from input object --      <id= "Updateuserbyid"  parametertype= "com. Higgin.Mybatis.po.User ">         update User set Username=#{username},birthday=#{birthday}, Sex=#{sex},address=#{address} where Id=#{id}     </update>

"Mybatistest.java"

@Test Public voidTestupdateuser ()throwsioexception{//mybatis Mapping FileString resource= "Sqlmapconfig.xml"; //get the MyBatis mapping fileInputStream inputstream=Resources.getresourceasstream (Resource); //creating sessions, passing MyBatis configuration informationSqlsessionfactory sqlsessionfactory=NewSqlsessionfactorybuilder (). Build (InputStream); //get the session through the factorySqlsession sqlsession=sqlsessionfactory.opensession (); User User=NewUser (); User.setid (4); User.setusername ("Taming Wang speaking 888"); User.setsex ("1"); User.setaddress (Beijing); User.setbirthday (NewDate ()); Sqlsession.update ("Test.updateuserbyid" , user); //Commit a transactionSqlsession.commit ();//You have to have it, or you can't plug in the data.//Close SessionSqlsession.close (); }

"Run Results"

05_ Updating data

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.