My experiences in solving webwork + spring + MySQL garbled characters today:
First, select GBK encoding when creating a database in MySQL;
Then, when Dao is called in the action, transcoding is not required, but the object displaying tags on the page needs to be transcoded. For example:
Unit. setunitid (targetunitvalue );
Unit. setunitname (targetvalue );
Unit. setstateid (unit. getstateid ());
Unit. setpeopleid (unit. getpeopleid ());
Boolean tempflag2 = xmdao. updateunitinfo (unit); // transcoding is not required
Unit. setunitname (encodingutil. textvalueencoding (targetvalue); // unit. unitname is displayed on the page label, so transcoding is required for encoding:
Encodingutil. textvalueencoding:
Public static string textvalueencoding (string content) {
If (content = NULL) {
return "";
}< br> try {
return new string (content. getbytes ("ISO-8859-1"), "GBK");
}< br> catch (exception e) {
E. printstacktrace ();
}< br> return NULL;
}< br>