In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to solve the problem of class error reporting in Controller layer and Service layer. It is very detailed and has a certain reference value. Interested friends must finish reading it!
Class error reporting of Controller layer and Service layer
When the following occurs, you can see if the jar package is missing from the pom.xml file.
When this happened to me, I went to look at the pom.xml package and found that if not, I was missing a jar package.
This is the jar spring-web that I am missing. Just add this to it.
The function of org.springframework spring-web 4.3.18.RELEASE Controller layer and Service layer 1. What kind of code do you write in controller and service?
Controller is literally a controller, so it is responsible for business scheduling, so some business scheduling code should be written in this layer, and the specific business processing should be written in service, and service is not just a call to add, delete, modify and query dao, service is the business layer, so it should be closer to the specific business function requirements, so in this layer, a method reflects a function that can be provided to the outside. For example, the method of generating orders in shopping malls is not as simple as adding an order record. We need to query inventory, check goods and other actual business logic processing.
two。 When will exceptions be added throughout the project? How to deal with exceptions?
Speaking of exceptions, we should recall what is the use of what an exception is when we learn the exception module? I have always thought that if there is an exception in the code, it makes me sad, because it means that I wrote something wrong, but now when I look back on the initial understanding, I think it's a bit funny, "people, who can make mistakes." the exceptions I understand are just errors that I think are caused, but I don't realize that there are a lot of exceptions in reality, except for self-causing problems, the server down, or the data state has changed. Even the outage of the network can cause anomalies, so on the other hand, anomalies serve us and exist for us to better find and solve problems. here, we really sincerely admire the predecessors who created the abnormal mechanism. their extraordinary wisdom is unmatched.
Back to the topic, so what should we do in practice?
Personally, I think we should do basic try-catch for each layer of code from the underlying dao to action. Sometimes we may have to do multiple catch according to business requirements, capturing all kinds of exceptions from small to large in turn. Generally, we should throw the underlying exceptions in order to inform the upper layer, that is, the caller, what is the problem. However, for the foreground that interacts directly with the user, it is inappropriate for the user to see these abnormal information in the background, so we need to convert the abnormal information to the user, and the abnormal information should be recorded in the log in order to analyze and solve the problem.
These are all the contents of this article entitled "how to solve the problem of Class error reporting in Controller layer and Service layer". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to 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.