Dao, Service, Controller layer function

1. Dao layer: the full name is Data Access Object. The Dao layer is relatively low-level, and is responsible for dealing with the database specific to the addition, deletion, and
modification of a table or an entity. 2. Service layer: also called the service layer or business layer, encapsulates the operation of the Dao layer, so that a method is externally manifested as a realization of one For example, when an order is generated for online shopping, it is not only necessary to insert the order information record, but also to check whether the product inventory is sufficient, whether the purchase exceeds the limit, and so on.
3. Controller layer: Controller is usually called Handler in the SpringMVC specification, and we sometimes understand this object as a back-end controller in the enterprise.

The Controller layer is like a waiter. He summarizes the taste, saltiness, and quantity of the dishes (data, requested type, etc.) ordered by the customer (front-end), and hands it to the chef (Service layer), and the chef tells the chef. The chef (Dao 1), the soup room (Dao 2), the side dish chef (Dao 3), etc. (collectively referred to as Dao layer) I need any semi-finished products, the assistant chefs (Dao layer) are responsible for completing the chef (Service) Assigned tasks. I don’t know if this analogy is appropriate.

@Controller
	
@RequestMapping("/goods/")
public class GoodsController {
     @RequestMapping("doGoodsUI")
public String doGoodsUI() {
	   return "goods";
}
}

 

@RequestMapping is equivalent to the configuration function of servlet in web.xml. Finding the corresponding servlet processing business is equivalent to entering the address http://localhost:8080/goods/doGoodsUI in the browser , and he knows the business name This code is out.

@RestController: It is equivalent to the combination of the two annotations @Controller+@ResponseBody. It is not necessary to add @ResponseBody annotation in front of the method to return json data.

Guess you like

Origin blog.csdn.net/wb_it_man/article/details/107447611