package com.wxl.sms.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxl.sms.bean.Group;
import com.wxl.sms.bean.Product;
import com.wxl.sms.bean.Provider;
import com.wxl.sms.bean.to.Check;
import com.wxl.sms.service.GroupService;
import com.wxl.sms.service.ProductService;
import com.wxl.sms.service.ProviderService;
import com.wxl.sms.service.SaleService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* 商品(Product)Controller
* PageHelper的一些数据: PageInfo中封装了详细的分页信息, 包括我们查询出的数据
* - pageNum: 当前页码
* - PageSize: 每页有多少条记录
* - startRow: 开始查询的记录
* - endRow: 结束的记录
* - ToTal: 总记录数
* - Pages: 总页码
* - firstPage/lastPage: 第一页/最后一页
* - isFirstPage/isLastPage: 是否第一页/是否最后一页
* - isHasPreviousPage/isHasNextPage: 是否有前一页/是否有后一页
*
*
* @author wxl on 2021/4/24 23:39
*/
@Controller
@RequestMapping("/product")
public class ProductController {
@Resource
private ProductService productService;
@Resource
private GroupService groupService;
@Resource
private SaleService saleService;
@Resource
private ProviderService providerService;
/**
* 查询所有商品库存信息(这里用到了PageHelper分页插件)
*
* @param pn 传入要查询的页码(要查询第几页的数据)
* @param model 为了将数据传入到cookie域中方便取出数据
* @return 返回product.jsp页面
*/
@RequestMapping("/productList")
public String getAllProducts(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
Model model) {
PageHelper.startPage(pn, 5);
// startPage后面紧跟的这个查询就是一个分页查询
List<Product> products = productService.getAllProducts();
// 使用PageInfo包装查询后的结果, 只需要将PageInfo交给页面就行了(param2:表示分页条显示的页数)
PageInfo<Product> pageInfo = new PageInfo<>(products, 5);
model.addAttribute("pageInfo", pageInfo);
// 2021年4月30日01:40:08添加, 为了让条件查询更容容易, 这里由填写商品分类, 修改为选择下拉框
List<Group> allGroups = groupService.getAllGroups();
model.addAttribute("allGroups", allGroups);
return "product/product";
}
/**
* [Deprecated]
* 用于搜索显示, 根据商品名称查询后显示 ---> 需要优化 ---> getProductInfoBySearch()
*
* @param request 从from表单中获取参数
* @param model 存数据
* @return 返回provider.jsp页面
*/
@Deprecated
@RequestMapping("/productName")
public String getProductByProductName(HttpServletRequest request,
Model model) {
String productName = request.getParameter("productNameInForm");
System.out.println(productName);
Product product = productService.getProductByProductName(productName);
// 虽然只有一条数据, 但是隔壁product.jsp取值还是从分页数据中取值的啊, 只好特殊对待了...(竟然能用)
List<Product> productListOnlyOne = new ArrayList<>();
productListOnlyOne.add(product);
PageInfo<Product> pageInfo = new PageInfo<>(productListOnlyOne, 5);
model.addAttribute("pageInfo", pageInfo);
List<Group> allGroups = groupService.getAllGroups();
model.addAttribute("allGroups", allGroups);
return "product/product";
}
/**
* [Deprecated]
* 对最初的搜索商品信息的优化方案 ===> 用于搜索显示, 根据商品名称查询后显示(PLUS版)
* 2021年5月10日13:22:04 ===> 方法有更新, 详情参阅Pro版
*
* @param pn 传入要查询的页码(要查询第几页的数据)
* @param request 用于获取表单中填写的值
* @param model 为了将数据传入到cookie域中方便取出数据
* @return 返回product.jsp页面
*/
@Deprecated
@RequestMapping("/search")
public String getProductInfoBySearch(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
HttpServletRequest request,
Model model) {
String productName = "";
Integer groupId = null;
// 表单输入的商品名称
if (request.getParameter("productNameInForm") != null) {
productName = request.getParameter("productNameInForm");
}
if (request.getParameter("groupIdInForm") != null &&
!request.getParameter("groupIdInForm").equals("0")) {
// 表单输入的商品类别
groupId = Integer.parseInt(request.getParameter("groupIdInForm"));
}
// System.out.println("~~~~~~++++++" + productName + "--> " + groupId);
PageHelper.startPage(pn, 5);
List<Product> products = productService.getProductByProductNameOrProductGroup(productName, groupId);
PageInfo<Product> pageInfo = new PageInfo<>(products, 5);
model.addAttribute("pageInfo", pageInfo);
List<Group> allGroups = groupService.getAllGroups();
model.addAttribute("allGroups", allGroups);
// model.addAttribute("selectedProductGroupId", groupId);
// // 根据id获取分类名
// Group searchGroup = groupService.getGroupByGroupId(groupId);
// model.addAttribute("selectedProductGroupName", searchGroup.getGroupName());
//
// System.out.println("%%%%%%--->" + groupId);
// System.out.println("%%%%%%--->" + searchGroup.getGroupName());
return "product/product";
// 2021年4月30日03:21:12(测试用)
// return "searchProduct";
}
/**
* “用于搜索显示, 根据商品名称查询后显示” 的Pro版
* 1、原先的方法, 按照商品类别搜索后, 点击该类别下的第二页时, 页面实际显示结果为所有商品列表的第二页 --> BUG
* 2、之前未解决的原因: 一直在想着怎么在点击超链接的时候提交表单
* 3、解决思路: 想要点击超链接的时候提交表单, 也就是为了获取表单里的groupId数据, 这里将点击搜索时用的groupId
* 以Model的格式传递到页面中(searchProduct.jsp), 下一次点击类似第二页的操作时, 获取到该分类的id号, 去取代
* 从表单中获取的值
* - 前提条件: 做了优化, 默认分类不是食品(遍历第一项), 而是提示信息, 并且值为 0, 后端处理时, 若值为0
* 则赋值productId为null, 此时MyBatis后端代码, 将不带有此条件(动态SQL);
* - 取代表单中获取的productId, 是有条件的, 如果用户什么也不填, 那Model返回的值就是null, 在方法处理时
* 添加了postGroupId默认值也为0, 如果为0, 那么就不接管替代表单值;
*
* @param pn 传入要查询的页码(要查询第几页的数据)
* @param request 用于获取表单中填写的值
* @param model 为了将数据传入到cookie域中方便取出数据
* @param postGroupId 存
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java的超市管理系统(用于毕业设计、课程设计).zip

共63个文件
java:28个
jsp:21个
xml:10个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 131 浏览量
2023-07-10
21:52:04
上传
评论
收藏 575KB ZIP 举报
温馨提示
本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!! 本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!! 本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!!
资源推荐
资源详情
资源评论



























收起资源包目录



























































































共 63 条
- 1
资源评论



白话机器学习
- 粉丝: 1w+
- 资源: 7629

下载权益

C知道特权

VIP文章

课程特权

开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于c++、easyx库的玫瑰花效果显示
- PQ控制三相并网逆变器:功率控制、PWM调制与LCL滤波器的应用及仿真模型学习交流,PQ控制三相并网逆变器:功率控制、PWM调制与LCL滤波器的应用及仿真模型学习交流,PQ控制三相并网逆变器,并网有功
- deepseek世上最全最详细的文档,包含10多个pdf文件
- 《绝区零》角色系统拆解
- 模拟退火算法与最低水平线算法结合的矩形排样与下料优化系统:输出最佳剩料率与水平线,支持数据替换优化,程序已调试完成可直接运行,模拟退火与最低水平线算法相结合的矩形排样与下料优化系统-实现剩余材料率优
- 双向全桥LLC谐振变换器与隔离型双向变换器的交流电网仿真研究:变频控制与闭环策略分析,双向全桥LLC谐振变换器与隔离型双向变换器的交流电网仿真研究:变频控制与闭环策略探讨,双向全桥LLC谐振变器并入交
- 《销售漏斗心理学》读书分享PPT
- 基于随机森林算法RF的多输入单输出数据回归预测-含详细注释的代码与性能评估指标(决定系数R2、平均绝对误差MAE、平均相对误差MBE),基于随机森林算法RF的多输入单输出数据回归预测-含详细注释的
- DCP9040CN-MFC9440CN维修手册(维修站)
- 全球商品和服务出口(1960 年至今,17特征)数据集 CSV
- 全球交通事故数据集(10,000 条交通事故报告记录,11特征)CSV
- 欧洲足球联赛的比赛统计数据集(23类赛事,244,038场比赛,7特征)CSV
- Python数据分析实例:基于航空公司客户飞行数据进行忠诚度分析及聚类建模
- 文化旅游数据集(5000 个样本,14特征)CSV
- 陨石登陆地球数据集(34,500+ 陨石着陆的详细记录,10特征)CSV
- 手机型号的详细规格数据集(900+记录,15特征)CSV
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
