In a Java program, if n methods in the program are placed in a Java transaction, a value may be used for each method. And as a thing, this value should be the same value, instead of being confused by multiple threads. In this case, when values are transferred between methods, stringbuffer is used to transmit a single string, MAP is used to pass two or more strings. (Note: when using map to pass values, parameters in map are of the object type. Therefore, if map needs to store two strings, put the two strings in two stringbuffer strings, and then put the two stringbuffer strings in the map.) The two stringbuffer strings can be created in the method (local variable ), the map parameter is passed during the transfer.
Example:
Synchronize a single string (mobilecode ):
Public int dabao (string tongdaoid, string mainid, stringbuffer Sb, connection conn) throws exception {.... while (RS. next () {mobilecode = Rs. getstring ("mobilecode ");}... SB. append (mobilecode); // put the mobilecode obtained in while into stringbuffer. The stringbuffer used in the next send call is here} public int send (string tongdaoid, string mainid, connection conn) throws exception {// call the stringbuffer int sjfsnumber = 0 added above; stringbuffer sb = new stringbuffer (); sjfsnumber = dabao (tongdaoid, mainid, Sb, conn); // send call dabao}
Synchronize two strings (mobilecode, clientid ):
Dabao () {stringbuffer b1 = new stringbuffer (); stringbuffer b2 = new stringbuffer (); b1.append (mobilecode); // put mobilecode in b2.append (clientid ); // put clientid in B2 map P = new hashmap (); p. put ("mobilecode1", B1); // This is caused by double quotation marks. It is the get name to get p at that time. Double quotation marks are used to cause p. put ("clientid1", B2); // in this way, put both strings in the map, and call} Send (MAP p) {string a = P. get ("mobilecode1"); // enclose string B = P. get ("clientid1 ");}
Extension:
Public void tx_duanxinadd (MAP p ){
P. Put ("key", value) can also be used for database queries. If ibatis is queried and placed in a <select ID ", you can use
P. Put ("field name", field value)
P. Remove ("field name") to clear the field value
P. Get ("field name ")