JAVA 类名称与类属性名一样,后端接收报类型转换转换错误

首先看实体类:

@Entity
@Table(name="sys_dict_type")
public class DictType extends BaseEntity implements Serializable{   
    /**
    * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
    */
    private static final long serialVersionUID = 1L;

    /** 字典主键 */
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Excel(name = "字典主键")
    @Column(name="dict_id")
    private Long dictId;

    /** 字典名称 */
    @Excel(name = "字典名称")
    @Column(name="dict_name",length=100)
    private String dictName;

    /** 字典类型 */
    @Excel(name = "字典类型 ")
    @Column(name="dict_type",length=100)
    private String dictType;

    /** 状态(0正常 1停用) */
    @Excel(name = "状态", readConverterExp = "0=正常,1=停用")
    @Column(name="status",columnDefinition="char(1)")
    private String status;
    public DictType() {       
    }

此处省略get,set

 

后端接收代码

 

@Controller
@RequestMapping("/system/dict")
public class DictTypeController extends BaseController {
    
    private String prefix = "system/dict/type";
    
    @Autowired
    private IDictTypeService dictTypeService;
    
    /*主页*/
    @RequiresPermissions("system:dict:view")
    @GetMapping()
    public String dictType()
    {
        return prefix + "/type";
    }
    
    
    /*
     * 主页数据
     * */
    @PostMapping("/list")
    @RequiresPermissions("system:dict:list")
    @ResponseBody
    public TableDataInfo list(@RequestBody DictTypeQoPg dictTypeQoPg)
    {       
        Page<DictType> page= dictTypeService.findDictTypeList(dictTypeQoPg);
        return getDataTable(page.getContent(),page.getTotalElements());
    }
    
    /**
     * 新增字典类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
    
    /**
     * 新增保存字典类型
     */
    //@Log(title = "字典类型", businessType = BusinessType.INSERT)
    @RequiresPermissions("system:dict:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DictType dict)
    {
        return toAjax(dictTypeService.insertDictType(dict));
    }
    
    /**
     * 校验字典类型
     */
    @PostMapping("/checkDictTypeUnique")
    @ResponseBody
    public String checkDictTypeUnique(DictType dict)
    {
        return dictTypeService.checkDictTypeUnique(dict);
    }
}

 

后台报类型转换错误:

2019-09-25 11:28:58.018  WARN 8136 --- [io-8080-exec-20] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'com.zcjd.project.system.dict.entity.DictType'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abcdefg'; nested exception is java.lang.NumberFormatException: For input string: "abcdefg"]

 

如果传过去的

居然成功了!!!!结果很明显是因为后台把接收到的dictType当成一个对像,而不是属性,导致了类型转换错误。

所以只要把DictType的   

/** 字典类型 */
    @Excel(name = "字典类型 ")
    @Column(name="dict_type",length=100)
    private String dictType;改为:
DictionaryType

问题解决。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值