个人错误集合

个人错误

无法访问org.springframework.web.bind.annotation.RestController

使用springboot3.0以上版本时,必须要使用java17,使用java8会报错,依赖改为3.0版本以下或使用java17

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.7.5</version>
      <relativePath/> <!-- lookup parent from repository -->
</parent>

无法访问jakarta.persistence.Column

这个错误是包引错了,应该是引入javax.persistence里面的column

If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

application.properties文件配置出错,检查datasource相关配置

java.lang.Integer cannot be cast to java.lang.Long

转换类型出错,不知道为什么Integer不能直接转换成Long类型,会报上面的错误,只能先用toString转换为String类型,再用Long.valueOf()转换为Long类型

Long empId = Long.valueOf(request.getSession().getAttribute("employee").toString());

从前端传入的json传空值时,输入后端变成null值

这种情况需要根据具体业务来修改,这里第一个参数含义是如果为true,就插入sql语句里面进行模糊查询,否则不进行模糊查询,其他情况下,可以使用if语句来进行判断

queryWrapper.lambda().like(null != selectCommodity.getId(), Commodity::getId, selectCommodity.getId())

There is no getter for property named ‘id’

这个错误是传id即可,但是我传了一个 mybatis-plus 条件构造器,这里直接获取传入数据的id就可以了,另外我在controller层接收前端数据时还忘了加@RequestBody

return commodityMapper.deleteById(commodityValue.getId());

argument type mismatch

这个错误是传入的参数类型不匹配,实现添加数据的操作时,传入的id为null,出现了这个错误,要么前端传入的id不为null,要么在实体类上加上@TableField(exist = false)注解,表示当前属性不是数据库的字段,但在项目中必须使用,可以实现增加数据的操作。(WDNMD删了之后又没问题了,建议重启idea试下)

@TableField(exist = false)
    private Integer id;

can not find lambda cache for this property [id] of entity [com.example.commodity.entity.CommodityValue]

这问题是由上一个问题引起的,遇到了就在mybatis-plus代码前面加TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), “”), TeamWorkerSearch.class) ;其中TeamWorkerSearch 是你要做条件的entity 对象,看别人是这么说的,我是把@TableField(exist = false)删掉了

Could not set property ‘id’ of ‘class com.example.commodity.dto.CommodityValue’ with value ‘xxx’

出现这个错误是在数据库将id设置为自增后,添加数据id为空时出现的,解决办法是在实体类id上添加注解@TableId(value = “id”,type = IdType.AUTO),把id设为自动增长

@TableId(value = "id",type = IdType.AUTO)
private Integer id;

Non-static method cannot be referenced from a static context

出现这个错误是在serviceImpl自动生成的方法里面更换类型后没有重新生成方法,直接在原有方法上进行修改,就会报静态上下文的错误

BaseMapper里面的方法需要实体类型,但提供的是实体类DTO类型,涉及类型转换

有两种解决办法,笨的是创建实体类对象,通过实体类对象设值把DTO里的数据当参数传进去,就可以拿到DTO里的数据而类型是实体类型
还有种办法就是使用工具类BeanUtils.copyProperties()来进行拷贝赋值

//updateById需要的是CommodityPropertyValue类型,而提供的是CommodityPropertyValueDto类型
        CommodityPropertyValue propertyValue = new CommodityPropertyValue();
        dto.setUpdateTime(time);
        dto.setUpdateUser("huang");
        BeanUtils.copyProperties(propertyValueDto,propertyValue);
        return commodityMapper.updateById(propertyValue);
        //propertyValue.setId(dto.getId());
        //propertyValue.setAbility(dto.getAbility());
        //propertyValue.setUpdateTime(time);
        //propertyValue.setUpdateUser("huang");
        //propertyValue.setMeasure(dto.getMeasure());
        //return commodityMapper.updateById(propertyValue);

Resolved [org.springframework.http.converter.HttpMessageNotReadableException

这个问题经常是使用apipost传的参数错误,检查一下格式,比如说需要传Integer类型的传了null,但数据库这个字段不能为null,还有多传了参数,少传了参数,还有忘记加逗号,Integer类型写成了字符串

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

这个错误网上说法是传入的参数为空,这个是对的,但我错在自动注入注解那里只写了一个@Autowired,下面写了两个mapper,而正确写法是一个mapper写一个@Autowired

Field ‘xxx’ doesn’t have a default value

这个错误是说字段没有默认值,原因是在数据库这条数据是不能为null的,但使用apipost是没有传这个参数,或者实体类表和数据传输类里面对应的数据库字段写错了

Access to XMLHttpRequest at ‘http://localhost:8080/propertyValue/select’ from origin ‘null’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

这个错误是跨域问题,在网上找一篇解决跨域的文章,一般里面都有写好了的配置,拿来用就行

实体类里面需要使用数据库没有的字段

在把数据处理成树状结构的时候在实体类里面添加了private List children=new ArrayList<>();列表来存储子级,当时是没问题的,但是在使用其他接口的时候会报错,说数据库里面没有这个字段,后来绕了好大一圈去把这个字段写在Dto里面,但还是失败了,因为使用beanutils.copyproperties需要两个类字段相同,但这样又要把列表写进实体类里面,所以还是失败了,后来才在网上看到可以把这个列表写在实体类里面,只要把这个字段忽略掉就可以了,在查询时会忽略这个字段,但在实现业务时可以用这个列表,使用@TableField(exist=false)就可以了,注解加载实体属性上,表示当前属性不是数据库的字段,但在项目中必须使用,这样在新增等使用实体的时候,mybatis-plus就会忽略这个,不会报错

导入项目后,点击maven更新出错org.skyscreamer:jsonassert:pom:1.5.0 failed to transfer from https://repo.maven.apache.org/maven2 during a previous attempt.

这个问题是你导入的项目本地maven仓库设置的是这个项目作者设置的位置,所以就算你之前设置过maven了,导入项目后也要重新设置一遍,不然就会出错,我就是记得自己设置过maven,但是不知道导入项目后还要重新更改所以怎么设置pom文件里面的依赖都会出错,升级版本,降低版本都没用,因为都跑到中央仓库去下载了,下载的慢不说,还经常出错

java: 无法访问org.springframework.beans.factory.annotation.Autowired错误的类文件: xxx/xxxx/xxxx,类文件具有错误的版本 61.0, 应为 52.0,请删除该文件或确保该文件位于正确的类路径子目录中。

这个错误是因为编译版本和你引入的spring版本不匹配,大概率是使用java8,然后引入的spring版本对应的是java17,需要在pom文件里把spring-boot-starter-parent的版本换成支持java8的版本

Cannot resolve method

出现这个错误看看lombok,经常是lombok出错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值