当前位置:   article > 正文

项目报错: Could not set property 'ID' of 'class cn.xxx.entity.vo.CrossVo' with value '1'_could not set property id of

could not set property id of

今天写mybatis的时候遇到一个问题轮饶了大半天,后来才发现自己犯了非常幼稚的错误,今天写了一个很简单的表,然后利用Mybatis的反向工具生成实体和BaseResultMap里面的字段,后来查询的时候,一直报错:Could not set property 'ID' of 'class cn.xxx.entity.vo.CrossVo' with value '1'

先看下生成后的实体:

  1. @TableName("rg_cross")
  2. @ApiModel(value = "路口表实体", description = "实体类")
  3. public class Cross extends Model<Cross> {
  4. private static final long serialVersionUID = 1L;
  5. /**
  6. * 路口主键id
  7. */
  8. @TableId(value="ID", type= IdType.AUTO)
  9. @ApiModelProperty(value = "路口主键id")
  10. private Long id;
  11. /**
  12. * 路口名称
  13. */
  14. @TableField("CROSS_NAME")
  15. @ApiModelProperty(value = "路口名称")
  16. @Length(min = 0, max =200, message = "路口名称长度不能超过200")
  17. private String crossName;
  18. /**
  19. * 路口经度
  20. */
  21. @TableField("LONGITUDE")
  22. @ApiModelProperty(value = "路口经度")
  23. @Length(min = 0, max =60, message = "路口经度长度不能超过60")
  24. private String longitude;
  25. /**
  26. * 路口纬度
  27. */
  28. @TableField("LATITUDE")
  29. @ApiModelProperty(value = "路口纬度")
  30. @Length(min = 0, max =60, message = "路口纬度长度不能超过60")
  31. private String latitude;
  32. /**
  33. * 是否是重要路口 1:是 0:否
  34. */
  35. @TableField("IS_IMPORTANT_ROAD")
  36. @ApiModelProperty(value = "是否是重要路口 1:是 0:否")
  37. private Integer isImportantRoad;
  38. public Long getId() {
  39. return id;
  40. }
  41. public void setId(Long id) {
  42. this.id = id;
  43. }
  44. public String getCrossName() {
  45. return crossName;
  46. }
  47. public void setCrossName(String crossName) {
  48. this.crossName = crossName;
  49. }
  50. public String getLongitude() {
  51. return longitude;
  52. }
  53. public void setLongitude(String longitude) {
  54. this.longitude = longitude;
  55. }
  56. public String getLatitude() {
  57. return latitude;
  58. }
  59. public void setLatitude(String latitude) {
  60. this.latitude = latitude;
  61. }
  62. public Integer getIsImportantRoad() {
  63. return isImportantRoad;
  64. }
  65. public void setIsImportantRoad(Integer isImportantRoad) {
  66. this.isImportantRoad = isImportantRoad;
  67. }
  68. @Override
  69. protected Serializable pkVal() {
  70. return this.id;
  71. }
  72. @Override
  73. public String toString() {
  74. return "Cross{" +
  75. ", id=" + id +
  76. ", crossName=" + crossName +
  77. ", longitude=" + longitude +
  78. ", latitude=" + latitude +
  79. ", isImportantRoad=" + isImportantRoad +
  80. "}";
  81. }
  82. }

再看我的BaseResultMap里面的字段

  1. <!-- 通用查询映射结果 -->
  2. <resultMap id="BaseResultMap" type="cn.xxx.entity.Cross">
  3. <id column="ID" property="id" />
  4. <result column="CROSS_NAME" property="crossName" />
  5. <result column="LONGITUDE" property="longitude" />
  6. <result column="LATITUDE" property="latitude" />
  7. <result column="IS_IMPORTANT_ROAD" property="isImportantRoad" />
  8. </resultMap>

再看我的查询语句:

  1. <select id="selectPage" resultMap="BaseResultMap">
  2. select rc.id,
  3. rc.CROSS_NAME,
  4. rc.LONGITUDE,
  5. rc.LATITUDE,
  6. rc.IS_IMPORTANT_ROAD
  7. from rg_cross rc
  8. <include refid="whereSql" />
  9. limit ${from}, ${size}
  10. </select>

正确的结果是这样的,

而我犯错的原因是没有BaseResultMap里面的 property跟我实体里面的小写一致,才导致这个错误。

注意点:BaseResultMap里面的 property的字段应该与实体中的字段保持一致

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/868463
推荐阅读
相关标签
  

闽ICP备14008679号