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

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条回答 默认 最新

查看更多回答(1条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持