In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the difference between dao and service in Spring". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The difference between dao layer and Service layer in springmvc
First of all, to explain the meaning on the surface, service is the business layer and dao is the data access layer. Oh, I used to have this problem. I remember that when I first learned programming, I used to call dao,service directly in service to new a dao class object. I didn't do other meaningful things. I don't understand what this is useful. after taking part in the work for a long time, I will know that business is the top priority in the work. As we all know, the standard mainstream programming methods now adopt the MVC integrated design pattern. MVC itself is not a kind of design pattern, it describes a structure, and the ultimate goal is to decouple. Decoupling means that if you change one layer of code, it will not affect my other layer code. If you can use a framework like spring, you will understand interface-oriented programming, the presentation layer calls the control layer, and the control layer calls the business layer. The business layer calls the data access layer. In the initial stage, it may be new objects to call the next layer, for example, if you new an object of a DAO class in the business layer, and call the DAO class method to access the database, this is wrong, because there should not be specific objects in the business tier, there can only be references, and if there are specific objects, they will be coupled. When that object doesn't exist, I have to modify the business code, which is illogical. For example, the memory on the motherboard is broken. I change the memory, so there is no need to change it with the motherboard. I do not need to know which memory is produced, do not know how much capacity, as long as the memory can be plugged into this interface. That's what MVC is all about. Next, you feel the meaning of service, in fact, because you are not so strict in doing things at different levels, and there is little business for you to do things. To take the simplest example, you do a paging function, with 1000 pieces of data, and you have 20 pieces in one page. You can write this function into a tool class and encapsulate it, and then call the encapsulated method in the business layer. This is what the business really does. As long as you don't access the database, you have to write it in the business. If you ask questions that you don't understand, this is a question of experience, hehe, in fact, you will understand later. Just at the beginning of the code is a request, I went to the database to get, almost no business.
This is the end of the content of "what is the difference between dao and service in Spring". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.