零食商城|基于springboot的零食商城(二)https://developer.aliyun.com/article/1423362
package com.yw.eshop.controller.admin; import com.yw.eshop.domain.User; import com.yw.eshop.service.UserService; import com.yw.eshop.utils.PageModel; import com.yw.eshop.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping("/admin") public class UserController { @Autowired private UserService userService; @RequestMapping("/user/list") public String list(@RequestParam(defaultValue = "1")Integer pageNo, @RequestParam(defaultValue = "10") Integer pageSize, Model model){ PageModel<User> userPages = userService.queryUserList(pageNo, pageSize); model.addAttribute("userPages",userPages); return "admin/user/list"; } @RequestMapping("/user/addPage") public String addPage(){ return "admin/user/add"; } @RequestMapping("/user/add") public String addUser(User user,Model model){ try { user.setType(0); int i = userService.addUser(user); if (i==0){ model.addAttribute("errMessage","服务器繁忙添加失败"); return "500"; } }catch (Exception e){ model.addAttribute("errMessage",e.getMessage()); return "500"; } model.addAttribute("url", "admin/user/list"); return "success"; } @RequestMapping("user/updatePage") public String updatePage(String id,Model model){ User user = userService.queryUserById(id); model.addAttribute("user",user); return "admin/user/update"; } @RequestMapping("/user/update") public String updateUser(User user,Model model){ try { int i = userService.updateUser(user); if (i==0){ model.addAttribute("errMessage","服务器繁忙修改失败"); return "500"; } }catch (Exception e){ model.addAttribute("errMessage",e.getMessage()); return "500"; } model.addAttribute("url", "admin/user/list"); return "success"; } @RequestMapping("user/deletePage") public String deletePage(String id,Model model){ model.addAttribute("id",id); return "admin/user/delete"; } @RequestMapping("user/delete") public String deleteUser(String id,Model model){ try { int i = userService.deleteUser(id); if (i==0){ model.addAttribute("errMessage","服务器繁忙修改失败"); return "500"; } }catch (Exception e){ model.addAttribute("errMessage",e.getMessage()); return "500"; } model.addAttribute("url", "admin/user/list"); return "success"; } }
package com.yw.eshop.controller.front; import com.yw.eshop.domain.Carousel; import com.yw.eshop.domain.Product; import com.yw.eshop.domain.ProductType; import com.yw.eshop.domain.SearchHistory; import com.yw.eshop.service.CarouselService; import com.yw.eshop.service.ProductService; import com.yw.eshop.service.ProductTypeService; import com.yw.eshop.service.SearchHistoryService; import com.yw.eshop.service.CarouselService; import com.yw.eshop.service.ProductService; import com.yw.eshop.service.ProductTypeService; import com.yw.eshop.service.SearchHistoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; @Controller @RequestMapping("/front") public class FrontIndexController { @Autowired//轮播图 private CarouselService carouselService ; @Autowired//商品类型 private ProductTypeService productTypeService ; @Autowired//商品 private ProductService productService ; @Autowired private SearchHistoryService searchHistoryService; @RequestMapping("/index") public String index(Model model){ //轮播图 List<Carousel> carousels = carouselService.queryCarouselAll(); model.addAttribute("allcarouselFigures",carousels); //分类 List<ProductType> productTypes = productTypeService.queryProductTypeAll(); model.addAttribute("allProductTypes",productTypes); //新品 List<Product> newProducts = productService.queryNewProduct(6); model.addAttribute("newProducts", newProducts); //查询热搜词 List<SearchHistory> searchHistorys = searchHistoryService.querySearchHistoryPages(10); model.addAttribute("searchHistorys",searchHistorys); //排行榜 List<Product> rankings = productService.queryProductRankings(); model.addAttribute("rankings", rankings); //饼干 ProductType productType = new ProductType(); productType.setProductTypeName("饼干"); Product product = new Product(); product.setProductType(productType); List<Product> list = productService.queryProductsByType(product, 5); model.addAttribute("list", list); //肉铺 productType.setProductTypeName("肉铺"); product.setProductType(productType); List<Product> list2 = productService.queryProductsByType(product, 12); model.addAttribute("list2", list2); //坚果 productType.setProductTypeName("坚果"); product.setProductType(productType); List<Product> list3 = productService.queryProductsByType(product, 5); model.addAttribute("list3", list3); //果干 productType.setProductTypeName("果干"); product.setProductType(productType); List<Product> list4 = productService.queryProductsByType(product, 12); model.addAttribute("list4", list4); return "front/index/index"; } }
五,项目总结
本项目功能完整,美观大方,数据完善,人机交互符合要求,是一个不错的毕业设计作品。