Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring mvc configure mybatis sql interceptor

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report