购物车加减商品后台
来源:互联网 发布:centos 7 ftp服务器 编辑:程序博客网 时间:2024/04/30 19:40
购物车加减
dao层
public interface GoodsMapper {
//定义查询所有商品的方法
public List<Goods> selectGoods();
//定义根据商品ID 查询数量的方法
public Integer selectCount(Integer id);
//定义一个根据商品ID 修改数量的方法
public void updateCount(@Param("id")Integer id,@Param("count")Integer count);
//定义根据商品ID 删除信息的方法
public void delete(Integer id);
}
<!-- 定义查询所有商品的方法 -->
<select id="selectGoods" resultType="goods">
select * from t_goods
</select>
<!-- 定义根据商品ID 查询数量的方法 -->
<select id="selectCount" parameterType="int" resultType="int">
select account from t_goods where id=#{id}
</select>
<!-- 定义一个根据商品ID修改数量的方法 -->
<update id="updateCount" >
update t_goods set account=#{count} where id=#{id}
</update>
<!-- 定义根据商品ID 删除信息的方法 -->
<delete id="delete" parameterType="int" >
delete from t_goods where id=#{id}
</delete>
service层
public interface GoodsService {
//定义查询所有商品的方法
public List<Goods> select();
//定义一个根据商品ID增加数量的方法
public void jiaCount(Integer id);
//定义一个根据商品ID删减数量的方法
public void jianCount(Integer id);
//定义根据商品ID 修改数量的方法
public void updateCount(Integer id,Integer count);
//定义根据商品id删除的方法
public void delete(Integer id);
}
实现类
public class GoodsServiceimpl implements GoodsService{
//注入工具类
@Autowired
private GoodsMapper gm;
//定义查询所有商品的方法
@Override
public List<Goods> select() {
// TODO Auto-generated method stub
//调用查询所有商品的方法
List<Goods> list = gm.selectGoods();
return list;
}
//实现增加数量的方法
@Override
public void jiaCount(Integer id) {
// TODO Auto-generated method stub
//调用根据ID查询数量的方法
Integer cou = gm.selectCount(id);
gm.updateCount(id, cou+1);
}
//实现删减数量的方法
@Override
public void jianCount(Integer id) {
// TODO Auto-generated method stub
//定义根据ID查询数量的方法
Integer cou = gm.selectCount(id);
gm.updateCount(id, cou-1);
}
//定义根据商品ID 删除商品的方法
@Override
public void delete(Integer id) {
// TODO Auto-generated method stub
//调用删除的方法
gm.delete(id);
}
//定义根据用户ID 修改数量的方法
@Override
public void updateCount(Integer id, Integer count) {
// TODO Auto-generated method stub
//调用修改的方法
gm.updateCount(id, count);
}
}
controller层
@Controller
@RequestMapping("goods")
public class GoodsController {
//注入服务类
@Autowired
private GoodsService gs;
//定义查询的方法
@RequestMapping("select")
@ResponseBody
public List select(HttpServletRequest request)
{
//调用方法
List<Goods> list = gs.select();
return list;
}
//定义增加数量的方法
@RequestMapping("jia")
@ResponseBody
public String jiacou(Integer id)
{
//调用增加数量的方法
gs.jiaCount(id);
return "ok";
}
//定义删减的方法
@RequestMapping("jian")
@ResponseBody
public String jiancou(Integer id)
{
//调用删减数量的方法
gs.jianCount(id);
return "ok";
}
//定义删除的方法
@RequestMapping("delete")
@ResponseBody
public String delete(Integer id)
{
//调用删除的方法
gs.delete(id);
return "ok";
}
//定义根据商品ID 修改数量的方法
@RequestMapping("updateCount")
@ResponseBody
public String uupdateCount(Integer id,Integer count)
{
//调用方法
gs.updateCount(id, count);
return "ok";
}
}
- 购物车加减商品后台
- ecshop优化2-商品页购买数量加减按钮ecshop购物车页加减按钮
- 【Kotlin】一个有趣的商品数量加减交互控件(商详页或者购物车商品数量的加减)
- 购物车加减控件
- 购物车数量加减
- 购物车实现加减
- 购物车加减按钮
- 购物车加减(bootsrap)
- 购物车加减
- 购物车加减
- 购物车加减
- ECSHOP 商品详情页 购物车页 添加购买数量加减按
- 购物车,追加商品
- 加入购物车与购物车加减
- js--购物车加减效果
- 简单购物车数量加减
- jquery购物车数量加减
- jquery购物车数量加减
- VirtualBox虚拟机中安装CentOS 7(四)安装常用工具
- 关于网格的开发环境
- okHttp管理cookie的简单方法
- Android 之Fragment
- SpirngMVC拦截器
- 购物车加减商品后台
- jstack学习 shell代码调试 set -x
- QT5.4.0实现QLabel滚动显示
- cookie和session
- 【POJ】1064
- 拓扑排序(模板)
- Java JDK 动态代理使用及实现原理分析
- 关于sklearn.svm.SVC与.NuSVC的区别以及参数介绍
- 读《Head First设计模式》