前端传递字符串类型的json数据数据,后端进行json转化并遍历集合进行数据存储(房价日历--修改)

    //房价日历--修改
    @ResponseBody
    @RequestMapping("/room/price/search/update")
    public Response search_update(@RequestBody JSONObject hotelRoomPriceGet) throws Exception  {
        String hotelRoomPriceGetStr = hotelRoomPriceGet.toJSONString();
        JSONObject jsonObject = JSON.parseObject(hotelRoomPriceGetStr);
        String obj = jsonObject.getString("obj");
        //将obj转换为hotelRoomPriceGet对象匹配格式
        List<HotelRoomPriceGet> hotelRoomPriceGets = JSON.parseArray(URLDecoder.decode(obj, "UTF-8"), HotelRoomPriceGet.class);
        if (!CollectionUtils.isEmpty(hotelRoomPriceGets)){
            for (HotelRoomPriceGet roomPriceGet : hotelRoomPriceGets) {
                Long product_id = roomPriceGet.getProduct_id();
                String date_start = roomPriceGet.getDate_start();
                String date_end = roomPriceGet.getDate_end();
                String price = roomPriceGet.getPrice();
                Date startDate = DateUtils.parseDate(date_start,"yyyy-MM-dd");
                Date endDate = DateUtils.parseDate(date_end,"yyyy-MM-dd");
                for (Date d = startDate;d.getTime()<=endDate.getTime();d=DateUtils.addDays(d, 1)){
                    hotelRoomPriceService.update(product_id,d,price);
                }
            }
            return new Response().success("修改房价成功");
        }else {
            return new Response().failed("修改房价失败,数据为空");
        }
    }
public class HotelRoomPriceGet {
	private Long product_id;//产品id
	private String date_start;//开始时间
	private String date_end;//结束时间
	private String price;//价格
}
           res.product_id = productId;
                                            res.date_start = startTime;
                                            res.date_end = endTime;
                                            res.price = price;
                                            arr.push(res)
                                            result["obj"] = arr;
                                        }
                                    })
                                    console.log(result)
                                    console.log(JSON.stringify(result))
                                    $.ajax({
                                        type: 'POST',
                                        url: '/room/price/search/update',
                                        // data: result,
                                        data: JSON.stringify(result),
                                        contentType : "application/json;charsetset=UTF-8",
                                        dataType: 'json',
                                        success: function (res) {
                                            console.log(res)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值