22、【收货地址管理模块】——收货地址增、删、改、查、分页列表、地址详情的功能开发
2018-10-14 10:35
477 查看
版权声明:转载请注明出处~ https://blog.csdn.net/czjlghndcy/article/details/83045150
在类上添加相关注解
1、接口开发:
新建
ShippingController类
在类上添加相关注解
@Controller @RequestMapping("/shipping/") public class ShippingController { }
1、收货地址的增加:
*Controller:
//添加地址接口 @RequestMapping(value = "add.do") @ResponseBody public ServerResponse add(HttpSession session, Shipping shipping){ User user =(User) session.getAttribute(Const.CURRENT_USER); if(user == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc()); } return iShippingService.add(user.getId(), shipping); }
*Service:
//收货地址添加方法 ServerResponse add(Integer userId, Shipping shipping);
*ServiceImpl:
//收货地址添加方法 public ServerResponse add(Integer userId, Shipping shipping){ shipping.setUserId(userId); shipping.setCreateTime(new Date()); shipping.setUpdateTime(new Date()); int rowCount=shippingMapper.insertSelective(shipping); if(rowCount>=0){ Map result= Maps.newHashMap(); result.put("shippingId",shipping.getId()); return ServerResponse.createBySuccess("新建地址成功",result); } return ServerResponse.createByErrorMessage("新建地址失败"); }
insertSelective是使用逆向工程生成的代码,所以直接调用即可。
2、收货地址删除的接口的开发:
*Controller:
//删除地址接口 @RequestMapping(value = "del.do") @ResponseBody public ServerResponse del(HttpSession session, Integer shippingId){ User user =(User) session.getAttribute(Const.CURRENT_USER); if(user == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc()); } return iShippingService.del(user.getId(), shippingId); }
*Service:
//删除收货地址方法 ServerResponse del(Integer userId,Integer shippingId);
*ServiceImpl:
//删除收货地址方法 public ServerResponse del(Integer userId,Integer shippingId){ int rowCount=shippingMapper.deleteByShippingIdByUserId(userId,shippingId); if(rowCount>0){ return ServerResponse.createBySuccess("删除地址成功"); } return ServerResponse.createByErrorMessage("删除地址失败"); }
由于为了防止横向越权的问题,我们使用自己封装的
deleteByShippingIdByUserId方法,在删除收货地址的时候,我们不仅判断收货地址的
Id,同时还判断该收货地址是否是在当前用户下。
*Mapper:
//同时根据用户Id和地址Id来删除地址,防止横向越权 int deleteByShippingIdByUserId(@Param("userId") Integer userId, @Param("shippongId") Integer shippongId);
*Mappler.xml:
<!--同时根据用户Id和地址Id来删除地址,防止横向越权--> <delete id="deleteByShippingIdByUserId" parameterType="map" > delete from mmall_shipping where user_id=#{userId} and id=#{shippongId} </delete>
3、收货地址修改的接口编写:
*Controller:
//修改地址接口 @RequestMapping(value = "update.do") @ResponseBody public ServerResponse update(HttpSession session, Shipping shipping){ User user =(User) session.getAttribute(Const.CURRENT_USER); if(user == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc()); } return iShippingService.update(user.getId(), shipping); }
*Service:
//修改地址接口 ServerResponse update(Integer userId,Shipping shipping);
*ServiceImpl:
//修改地址方法 public ServerResponse update(Integer userId,Shipping shipping){ shipping.setUserId(userId); Shipping selship=shippingMapper.selectByShippingIdByUserId(userId,shipping.getId()); if(selship == null){ return ServerResponse.createByErrorMessage("该用户不存在此地址"); }else { int rowCount= shippingMapper.updateByshipping(shipping); if(rowCount>=0){ Map result= Maps.newHashMap(); result.put("shippingId",shipping.getId()); return ServerResponse.createBySuccess("更新地址成功",result); } } return ServerResponse.createByErrorMessage("更新地址失败"); }
updateByshipping方法:
*Mapper:
//修改地址接口 int updateByshipping(Shipping record);
*Mappler.xml:
<!--更新地址--> <update id="updateByshipping" parameterType="com.mmall.pojo.Shipping"> update mmall_shipping set receiver_name = #{receiverName,jdbcType=VARCHAR}, receiver_phone = #{receiverPhone,jdbcType=VARCHAR}, receiver_mobile = #{receiverMobile,jdbcType=VARCHAR}, receiver_province = #{receiverProvince,jdbcType=VARCHAR}, receiver_city = #{receiverCity,jdbcType=VARCHAR}, receiver_district = #{receiverDistrict,jdbcType=VARCHAR}, receiver_address = #{receiverAddress,jdbcType=VARCHAR}, receiver_zip = #{receiverZip,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = now() where id = #{id,jdbcType=INTEGER} and user_id = #{userId,jdbcType=INTEGER} </update>
4、查询地址接口:
*Controller:
//查询地址接口 @RequestMapping(value = "select.do") @ResponseBody public ServerResponse select(HttpSession session, Integer shippingId){ User user =(User) session.getAttribute(Const.CURRENT_USER); if(user == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc()); } return iShippingService.select(user.getId(), shippingId); }
*Service:
//查询收货地址的方法 ServerResponse<Shipping> select(Integer userId,Integer shippingId);
*ServiceImpl:
//查询收货地址的方法 public ServerResponse<Shipping> select(Integer userId,Integer shippingId){ Shipping shipping=shippingMapper.selectByShippingIdByUserId(userId,shippingId); if(shipping == null){ return ServerResponse.createByErrorMessage("无法查询到该地址"); } return ServerResponse.createBySuccess("查询地址成功",shipping); }
*Mapper:
```//查询收货地址接口 Shipping selectByShippingIdByUserId(@Param("userId") Integer userId, @Param("shippongId") Integer shippongId);
*Mappler.xml:
<select id="selectByShippingIdByUserId" resultMap="BaseResultMap" parameterType="map" > select <include refid="Base_Column_List"/> from mmall_shipping where id= #{shippongId} and user_id=#{userId} </select>
5、查询所有地址接口开发(带分页):
*Controller:
//查询所有地址接口(带分页) @RequestMapping(value = "list.do") @ResponseBody public ServerResponse<PageInfo> list(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum, @RequestParam(value = "pageSize",defaultValue = "10") int pageSize, HttpSession session){ User user =(User) session.getAttribute(Const.CURRENT_USER); if(user == null){ return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc()); } return iShippingService.list(user.getId(),pageNum,pageSize); }
*Service:
//查询所有收货地址的方法 ServerResponse<PageInfo> list(Integer userId, int pageNum, int pageSize);
*ServiceImpl:
//查询所有收货地址的方法 public ServerResponse<PageInfo> list(Integer userId,int pageNum, int pageSize){ PageHelper.startPage(pageNum,pageSize); List<Shipping> shippingList=shippingMapper.selectByUserId(userId); PageInfo pageInfo= new PageInfo(shippingList); return ServerResponse.createBySuccess(pageInfo); }
*Mapper:
//查询所有收获地址接口 List<Shipping> selectByUserId(Integer userId);
*Mappler.xml:
<select id="selectByUserId" resultMap="BaseResultMap" parameterType="map"> select <include refid="Base_Column_List"/> from mmall_shipping where user_id=#{userId} </select>
2、接口测试:
1、收货地址接口测试
2、收货地址删除的接口测试
3、收货地址修改的接口测试
4、查询地址接口测试
5、查询所有地址接口测试
相关文章推荐
- 【收货地址管理模块】——收货地址增、删、改、查、分页列表、地址详情的功能开发
- 程序开发管理系统功能模块
- [置顶] Struts2+Hibernate4开发学生信息管理功能--(四)学生信息管理模块
- SNF软件开发机器人-子系统-功能-数据列表分页与不分页-瀑布式分页-如何配置?
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- Winform开发框架中的内容及文档管理模块功能介绍
- 基于ArcGIS10.0和Oracle10g的空间数据管理平台二(C#开发)-登录功能模块
- RDIFramework.NET ━ .NET快速信息化系统开发框架 - 4.9 操作(功能)权限管理模块
- 模块管理常规功能自定义系统的设计与实现(22--第二个模块的加入)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- 电商平台搭建--分类管理功能模块开发
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- 模块管理常规功能自己定义系统的设计与实现(22--第二个模块的增加)
- ZendFramework2开发-列表分页功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- [置顶] Struts2+Hibernate4开发学生信息管理功能--(三)用户登录模块
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->新增模块管理界面导出功能(可按条件导出)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->新增模块管理界面导出功能(可按条件导出)