In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to solve the hump naming problem of SpringBoot data source integration. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
There is a small problem, that is, the field about hump naming has not been queried, that is to say, our hump naming rules are not valid. SpringBoot how to integrate multiple data sources, read this article is enough, you can clearly see that our time value is not queried, then I will talk to you today about the solution to this problem.
@ Bean (name = "test2SqlSessionFactory") public SqlSessionFactory test2SqlSessionFactory (@ Qualifier ("test2DataSource") DataSource dataSource) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean (); bean.setDataSource (dataSource); bean.setTypeAliasesPackage ("com.example.mapper.test2"); org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration (); / / enable hump naming convention configuration.setMapUnderscoreToCamelCase (true); bean.setConfiguration (configuration) / / configure the address of the xml file bean.setMapperLocations (new PathMatchingResourcePatternResolver () .getResources ("classpath:mapper/test1/*.xml")); return bean.getObject ();}
We only need to add the middle few lines of code to the class configured yesterday to open the hump naming rule. Both configuration files need to be configured, and then we'll take a look at the results.
At this time, the naming of our whole hump will be taken care of. In addition, if you do not configure this, there is another problem, that is, if your sql is written in the xml file, then your interface does not correspond to the xml file, it will report an error. Let's see what the error will be.
Our sql is written in the xml file
Let's take a look at the error message that does not configure the xml address
You can clearly see that the method cannot be found, which means that if we do not configure the xml address in the configuration file of each data source, then this error will occur. Let's configure it and look at the results.
At this time, we can get the correct results. I would like to add the questions left over from the previous article to you today. I hope you can understand something after reading it, instead of looking at it roughly. As a result, I wrote all kinds of pits, resulting in no effect. I climbed these pits in advance and shared them with you in time. I hope you can grow up together.
Ps: last time, I said that I originally wrote about payment today, but as a result, I would like to make up for any remaining problems. In the next article, I will write about the pit encountered by WeChat Pay, which we should already pay attention to.
The above is how to solve the hump naming problem of SpringBoot integrated data sources. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.