渺沧海一粟667 2021-08-30 15:00 采纳率: 71.4%
浏览 109
已结题

ajax 传json数据 400 405 500

json前端显示是传递过去的。

img

直接上报错。百度了好多都解决不了

30-Aug-2021 14:48:51.906 警告 [http-nio-8080-exec-9] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `int` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `int` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (PushbackInputStream); line: 1, column: 1]]

感觉是我代码错了。附上代码大伙帮忙看看。
可能错误 个人感觉
1.ajax传time类型值。冒号被解析成%3A
2.json后端的读取

//实体类属性有添加注解
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date appointmentDate;
@DateTimeFormat(pattern = "HH:mm:ss")
private Time startTime;
@DateTimeFormat(pattern = "HH:mm:ss")
private Time endTime;
//controller层用@RequestBody接收不知道写的对不对
    @RequestMapping("/orderAppointment")
    @ResponseBody
    public String orderAppointment(@RequestBody int userUid, @RequestBody Date appointmentDate,@RequestBody Time startTime, @RequestBody Time endTime, @RequestBody int roomUid, @RequestBody int state){
        int sum = userService.countAllAppointment();
        System.out.println("userUid:"+userUid+"appointmentDate:"+appointmentDate+"startTime:"+startTime+"endTime:"+endTime+"roomUid"+roomUid+"state:"+state);
        Appointment appointment = new Appointment(userUid, 300+sum, appointmentDate, startTime, endTime, roomUid, state);
        int res = userService.checkAppointment(appointment);
        if (res>0){
            return "fail";
        }else {
            int res1 = userService.addAppointmentInfo(appointment);
            int res2 = userService.addAppointment(appointment);
            if (res1>0&&res2>0){
                return "success";
            }else {
                return "fail";
            }
        }
    }

//ajax  发送ajax请求的时候前端能把json打印出来

                        $.ajax({
                            url: '/orderAppointment',
                            type: 'post',
                            contentType:'application/json;charset=utf-8',
                            dataType: 'text',
                            data: JSON.stringify({
                                'userUid': userUid,
                                'roomUid': roomUid,
                                'appointmentDate': appointmentDate,
                                'startTime': startTime,
                                'endTime': endTime,
                                'state': state
                            }),
                            success: function (res) {
                                if (res == "success") {
                                    layer.msg('预约成功!');
                                } else {
                                    layer.msg("对不起,预约失败.");
                                }
                            }
                        });
  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 已结题 (查看结题原因) 8月30日
      • 已采纳回答 8月30日
      • 创建了问题 8月30日

      悬赏问题

      • ¥30 关于#c++#的问题:用C++编程实现主存-Cache地址映射(附运行成功截图+注释)
      • ¥25 接口/特征方法的异常错误返回如何判断是否需要设计
      • ¥40 代码+预测分析,文件私信发哦(价格可商量)
      • ¥15 GAMES101 HW1 无法定义
      • ¥15 pycharm不管允许什么代码都出错,都会出现下面的情况。
      • ¥15 boost::integrate的用法
      • ¥20 51单片机输出pwm时无法调节频率,如何解决?
      • ¥15 DSP28335 AD采集正弦波
      • ¥50 pwwinauto调式修改
      • ¥30 关于#单片机#的问题:单片机基于51单片机开发计时器,使其实现以下功能:(1)开发板上四个独立按键分别控制计时器的启停、计时器的复位(按下计时值归零)、计时位切换、计时时间的递增