Spring mvc configure mybatis sql interceptor
Go directly to the code:
Add the following to the mybatis configuration:
Classpath:/com/*/maper/*.map.xml
There is no plugins attribute in some SqlSessionFactoryFactoryBean classes
(private Interceptor [] plugins; generates setter method)
Add the plug-in to Configuration conf = sqlSessionFactory.getConfiguration () after defining the attribute; as follows
If (nullified principthis.plugins) {
For (Interceptor plugin: this.plugins) {
Conf.addInterceptor (plugin)
If (this.logger.isDebugEnabled ()) {
This.logger.debug ("Registered plugin:'" + plugin + "'")
}
}
}
About intercepting PageInterceptor
If you want to save the value question for sql and sql:
Sql data problem: special symbols in sql cannot be saved to the database. They are encoded by url and saved to the database. If you want to view them, you can reverse the code.
The problem of sql corresponding value: 1. Object into json data, 2, get the data directly
Public static String getStringParame (Object obj) {
JSONObject json = JSONObject.fromObject (obj); / / convert java objects to json objects
String str = json.toString (); / / convert the json object to a string
/ / the string is not returned directly by json
If (str.equals (") | | str.equals (" {} ")) {
Str = obj.toString ()
}
Return str
}