In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to achieve the separation of mysql reading and writing". In the daily operation, I believe that many people have doubts about how to achieve the separation of mysql reading and writing. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve mysql reading and writing separation". Next, please follow the editor to study!
One purpose
First of all, prepare a web website, here simulate the page of a website, mainly realize the dynamic access to the open source web page, and then use this page to further realize the read-write separation of mysql.
Two architectures
The foreground is the page of the open source web page.
Springboot+thymeleaf development is adopted in the background.
1 front-end page integration
Copy the website instance page and go to the following path / template/case1page
Copy static pages including js files to / static
2 background integration
Add corresponding jar package dependencies to Pom, and it is not convenient for developers to add hot deployment related dependencies, such as
Org.springframework.boot
Spring-boot-maven-plugin
Org.springframework
Springloaded
1.2.1.RELEASE
Integrate mybatis
The method of writing to set up the injection data source and SqlSessionFactory in Application is as follows
@ Bean
@ ConfigurationProperties (prefix= "spring.datasource")
Public DataSource dataSource () {
Return new org.apache.tomcat.jdbc.pool.DataSource ()
/ / com.alibaba.druid.pool.DruidDataSource ()
}
3 database design
Two tables, SD_CATEGORY,SD_LABLE_SWITCH, are mainly used to store the relevant detailed data in the title and the title of the corresponding page. For specific tables and data, please see the attached script.
Three practical functions
The dynamic effect of 12 demo is realized in the page.
The 11th demo has been taken as an example. Explain the way of implementation
1 the data style in the static page is as follows
Journalism
News home page
Headliner
News television
News picture
News video
News feature
Trailer
News home page
Headliner
News television
News picture
News video
News feature
According to the way the data is displayed above, the structure of storing data in the background is to use an object to store title and entry data (List), and then a group list to store these objects, which corresponds to the structure of the page.
2 the page is displayed as follows
Journalism
News home page
Backstage storage mode
The logic for organizing data in the controller that processes the corresponding demo instance is as follows
/ / find the title
List grpTitle = userService.getGrpTitle (caseId)
/ / when looking up each title, find all the corresponding lable data and put in a grplist
For (GrpTitle title: grpTitle) {
List lable = userService.getLableInfo (title.getGRP_ID ())
FullContent cont = new FullContent ()
Cont.setTP_NM (title.getTP_NM ())
Cont.setLable (lable)
/ / put all grplist into one list
GrpList.add (cont)
}
/ / join case1 to return the required result
Model.addAttribute ("grp11List", grpList)
At this point, the study on "how to achieve the separation of mysql reading and writing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.