web请求,请求参数
{name: "zhansan", description: "飒飒大讲述了克里斯",…}
description:"飒飒大讲述了克里斯"
functions:[{id: 1}, {id: 41}, {id: 47}, {id: 49}, {id: 50}]
name:"zhansan"
后台接收参数方法:
@RequestMapping("/saveOrUpdate")
public @ResponseBody ResponseEntity<String> saveOrUpdate(@RequestBody Role role) {
roleService.saveOrUpdate(role);
return ResponseEntity.ok("success");
}
返回结果:
{
"timestamp":1493972641002,
"status":500,
"error":"Internal Server Error",
"exception":"com.alibaba.fastjson.JSONException",
"message":"java.lang.Integer cannot be cast to java.lang.Long",
"path":"/role/saveOrUpdate.htm"
}
Role 对象中存在一个function对象的集合,function对象中id 的属性类型是Long类型,结果报错java.lang.Integer cannot be cast to java.lang.Long,这个问题是怎么导致的,而且这个问题是有时候会出现,有时候不会出现,怎么解决?
package com.control.back.halo.manage.entity;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import com.control.back.halo.basic.entity.BaseEntity;
@Entity
@Table(name = "sys_role")
public class Role extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 820694530776191567L;
// fields
private java.lang.String name;
private java.lang.String description;
// collections
@ManyToMany(mappedBy = "roles")
private java.util.Set<Admin> admins;
@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinTable(name = "sys_role_function", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "function_id") })
private java.util.Set<Function> functions;
/**
* Return the value associated with the column: NAME
*/
public java.lang.String getName() {
return name;
}
/**
* Set the value related to the column: NAME
*
* @param name
* the NAME value
*/
public void setName(java.lang.String name) {
this.name = name;
}
/**
* Return the value associated with the column: DESCRIPTION
*/
public java.lang.String getDescription() {
return description;
}
/**
* Set the value related to the column: DESCRIPTION
*
* @param description
* the DESCRIPTION value
*/
public void setDescription(java.lang.String description) {
this.description = description;
}
/**
* Return the value associated with the column: admins
*/
public java.util.Set<Admin> getAdmins() {
return admins;
}
/**
* Set the value related to the column: admins
*
* @param admins
* the admins value
*/
public void setAdmins(java.util.Set<Admin> admins) {
this.admins = admins;
}
/**
* Return the value associated with the column: functions
*/
public java.util.Set<Function> getFunctions() {
return functions;
}
/**
* Set the value related to the column: functions
*
* @param functions
* the functions value
*/
public void setFunctions(java.util.Set<Function> functions) {
this.functions = functions;
}
}
Integer放不下时间戳,改成Long即可
Integer放不下时间戳,改成Long即可
这个timestamp?
我说的不是时间戳类型转换建议把实体类贴出来,不然数据类型都看不到,异常描述的很清楚,类型转换错误
回复 @夜丶魂:你看吧回复 @hiyou:Role实体类的代码贴出来你能不能仔细看看看不出什么异常Function和Admin都看不到,把代码剥离出来,直接用fastjson把你那段json转换成Role测试下
回复 @hiyou:不用谢,毕竟没有帮到你恩,谢谢指点版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。