【出荷先住所管理モジュール】——出荷先住所の増加、削除、変更、調査、ページングリスト、住所詳細の機能開発

45041 ワード

1、インタフェースの開発:
新しいShippingControllerクラスクラスクラスクラスに関連注釈を追加
@Controller
@RequestMapping("/shipping/")
public class ShippingController {

}
  • 1
  • 2
  • 3
  • 4
  • 5

  • 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);
        }
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    *Service:

     //        
        ServerResponse add(Integer userId, Shipping shipping);
    
       
       
       
       
    • 1
    • 2

    *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("      ");
        }
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    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);
        }
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    *Service:

    //        
        ServerResponse del(Integer userId,Integer shippingId);
    
       
       
       
       
    • 1
    • 2

    *ServiceImpl:

      //        
        public ServerResponse del(Integer userId,Integer shippingId){
    
        int rowCount=shippingMapper.deleteByShippingIdByUserId(userId,shippingId);
        if(rowCount>0){
            return ServerResponse.createBySuccess("      ");
        }
        return ServerResponse.createByErrorMessage("      ");
    }
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

  • 横越権の問題を防止するために,我々は自分でカプセル化したdeleteByShippingIdByUserId手法を用いて,出荷先を削除する際に,出荷先のIdだけでなく,その出荷先が現在のユーザの下にあるか否かを判断する.*Mapper :
    //      Id   Id     ,      
        int deleteByShippingIdByUserId(@Param("userId") Integer userId, @Param("shippongId") Integer shippongId);
    
       
       
       
       
    • 1
    • 2

    *Mappler.xml:

    
      <delete id="deleteByShippingIdByUserId" parameterType="map" >
        delete
        from mmall_shipping
        where user_id=#{userId}
        and id=#{shippongId}
      delete>
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    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);
        }
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • *Service :
    //      
        ServerResponse update(Integer userId,Shipping shipping);
    
       
       
       
       
    • 1
    • 2

    *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("      ");
    }
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • updateByshippingメソッド:*Mapper:
      //      
        int updateByshipping(Shipping record);
    
       
       
       
       
    • 1
    • 2

    *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>
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    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);
        }
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • *Service :
     //         
        ServerResponse<Shipping> select(Integer userId,Integer shippingId);
    
       
       
       
       
    • 1
    • 2

    *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);
        }
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    *Mapper:

    
    ```//        
        Shipping selectByShippingIdByUserId(@Param("userId") Integer userId, @Param("shippongId") Integer shippongId);
    
       
       
       
       
    • 1
    • 2
    • 3

    *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>
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    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);
        }
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    *Service:

    //           
        ServerResponse<PageInfo> list(Integer userId, int pageNum, int pageSize);
    
       
       
       
       
    • 1
    • 2

    *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);
    }
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • *Mapper :
     //          
        List<Shipping> selectByUserId(Integer userId);
    
       
       
       
       
    • 1
    • 2

    *Mappler.xml:

    <select id="selectByUserId" resultMap="BaseResultMap" parameterType="map">
        select
        <include refid="Base_Column_List"/>
        from mmall_shipping
        where user_id=#{userId}
      select>
    
       
       
       
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2、接口测试:

    1、收货地址接口测试
    2、收货地址删除的接口测试
    3、收货地址修改的接口测试
    4、查询地址接口测试
    5、查询所有地址接口测试