"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