几周前我开始使用 Spring Boot,但我仍然无法理解“AbstractController”的概念。
public abstract class AbstractController {
protected static final String CUSTOMER_SESSION_ID = "auth";
protected static final String SHOOPY_CART_ID = "SHOOPY_CART";
protected static final String REFERER_HEADER = "Referer";
@Autowired
protected CatalogService catalogService;
@Autowired
protected TotalAmountCalculator amountCalculator;
@Autowired
protected CustomerRepository customerRepo;
@Autowired
protected CartRepository cartRepository;
//Insert necessary data to the header tag
public void populateHeaderData(Model model, Cart activeCart) {
HeaderDTOBuilder.HeaderDTO headerDTO = new HeaderDTOBuilder().
withAmountCalculator(amountCalculator)
.withActiveCart(activeCart)
.withCategories(catalogService.getCategories()).build();
model.addAttribute("headerDTO", headerDTO);
}
public void populateHeaderData(Model model, HttpServletRequest request) {
Cart activeCart = getCartFrom(request);
if(activeCart == null){
activeCart = new Cart();
}
populateHeaderData(model, activeCart);
}
}
我很想了解 Controller 和 AbstractController 之间的区别。
杨__羊羊
莫回无
相关分类