若依二次开发问题汇总

前端小白在开发过程中遇到的问题,在此记录

若依 Error: 请求参数类型不匹配,参数[xxx]要求类型为:‘xxx’,但输入值为:‘xxx’

打开对应页面后端controller,与前端.js文件

  1. 检查映射路径是否正确(仔细检查路径名)。
  2. 如有形参的话检查形参名和类型。

注意的地方:

  1. 权限问题。一般是登录最高权限进行开发,不是主要问题,但也需要注意和当前页面对得上,不要复制成之前的权限。
  2. 在同一文件夹下存放多个.js时,如果存在相同的方法名(直接复制过去的)可能会出现串用的情况,严重的则会报错,若代码检查无误时,可以尝试修改方法名使其不重复的方式。

出现ambiguous的一大堆报错

Uncaught (in promise) Error: 
### Error querying database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'xxx' in where clause is ambiguous
### The error may exist in file [D:\...\xxx.xml]
### The error may involve xxx.xxxMapper.xxx-Inline
### The error occurred while setting parameters
### SQL: SELECT count(0) FROM ...
### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'xxx' in where clause is ambiguous
; Column 'xxx' in where clause is ambiguous; nested exception is 
java.sql.SQLIntegrityConstraintViolationException: Column 'post_id' in where clause is ambiguous
    at _default (request.js?xxxx:xx)

这个是SQL语句中,因为有的表有相同的字段,但是多表联合的过程中没有通过别名进行区分,大多发生在where条件中,因为在写表的联合时一般会进行测试,看能否正常运行。

前端JS请求无法被后端接收到,但权限和路径无误

修改请求的名称,别与其他的重复,也别与路径中的字段重复

一大堆报错2

Uncaught (in promise) Error: nested exception is org.apache.ibatis.type.TypeException: 
Could not set parameters for mapping: 
ParameterMapping{property='xxx', mode=IN, javaType=class java.lang.String, jdbcType=null, 
numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. 
Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . 
Try setting a different JdbcType for this parameter or a different configuration property. 
Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
    at _default (request.js?b775:95)

去后端跟踪一下直到xml文件,检查对应的parameterType是不是和形参的类型对应上了。

一大堆报错3

Uncaught (in promise) Error: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: 
Expected one result (or null) to be returned by selectOne(), but found: 3
    at _default (request.js?b775:95)

这里说明返回的结果本应该是空或者只有一个,一般是查询主键,但是却查出来3个,说明是查询条件where写错了。

导入报错

导入失败:nested exception is org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named 
'segment' in 'class x.xx.xxx.xxxxx.xxxxx.domain.xxxx'

很简单,检查数据库中对应表的字段和自己写的xml文件,是不是里面segment字段不存在。
这里记得要用查找的方式来修改,因为你也不知道你哪个地方忘了改,导致这个问题一直不能解决。

时间格式报错

### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: 
Data truncation: Incorrect date value: 'Thu Aug 03 00:00:00 CST 2023' for column 'depart_date' at row 1 
### The error may exist in file [D:\IdeaProjects\RuoYi-Vue-master\ruoyi-system\target\classes\mapper\system\sm\hr\SmHrUserDepartInfoMapper.xml] 
### The error may involve com.ruoyi.system.sm.hr.mapper.SmHrUserDepartInfoMapper.updateSmHrUserDepartInfo-Inline 
### The error occurred while setting parameters ### SQL: update sm_hr_user_info SET employee_code = ?, 
employee_name = ?, post_id = ?, manager_level_id = ?, password = ?, depart_date = ?, depart_reason = ? 
where id = ? 
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: 
Incorrect date value: 'Thu Aug 03 00:00:00 CST 2023' for column 'depart_date' at row 1 ; 
Data truncation: Incorrect date value: 'Thu Aug 03 00:00:00 CST 2023' for column 'depart_date' at row 1; 
nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: 
Data truncation: Incorrect date value: 'Thu Aug 03 00:00:00 CST 2023' for column 'depart_date' at row 1

这个时候最好全都用Date格式进行输入,而不是String,Date格式可以直接送入到数据库中。但是在实际应用中,当涉及到Excel导出时,体验并不好,所以依然保留String格式。
我使用的解决办法:自定义下面所示的函数,并使用,将其转换成为yyyy-MM-dd格式并进行验证:

/**
     * 将日期字符串转为yyyy-MM-dd格式
     *
     * @param sDate 日期字符串
     * @return 返回与日期字符串相对应的yyyy-MM-dd格式,并检查是否为能成功转换成日期,若转换失败则返回NULL
     */
    public String StringDateTransfer(String sDate){
        if(sDate.indexOf("CST") != -1){// 是CST格式的
            try {
                SimpleDateFormat sim = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
                Date date = sim.parse(sDate);
                // 然后Date转String
                return new SimpleDateFormat("yyyy-MM-dd").format(date);
            }catch (ParseException e ){
                return null;
            }
        }
        StringBuilder strBuilder = new StringBuilder(sDate);
        for(int i = 0; i < strBuilder.length() && i < 10; i ++ ){
            char ch = strBuilder.charAt(i);
            if(ch == '/'){
                strBuilder.setCharAt(i, '-');
            }
        }
        String retDate = sDate;// 返回的参数,这里的形参是引用类型的
        sDate = strBuilder.toString();
        if(CheckDateStringFormat(sDate)) return retDate;
        return null;
    }

    /**
     * 检查日期字符串是否为yyyy-MM-dd格式
     *
     * @param sDate 日期字符串
     * @return 失败则返回false
     */
    public boolean CheckDateStringFormat(String sDate){
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        try {
            Date temp = sdf.parse(sDate);
        }catch (ParseException e){
            return false;
        }
        return true;
    }

若要获取当前时间,则直接:

String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());

在导出到Excel表格时,日期格式错误

与上一个相反,这个情况需要把日期格式改为String而不是Date才行。但是全部转String了之后发现如果是yyyy-MM-dd形式的日期不会报上面的错,只有yyyy/MM/dd格式的会,因为手动写入excel表格时会自动转换成yyyy/MM/dd,导出时不会。

在自动生成的代码中取消Spring Security加密

这个是因为自己的密码字段需要明文查看,所以不选择加密。
只需将下面的这个字段注释掉,一般位置在mpl.java,可全局搜索去找。

user.setPassword(SecurityUtils.encryptPassword(password));

主键重复

### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: 
Duplicate entry '0100323' for key 'sm_hr_user_info_u1' 
### The error may exist in file 
[D:\IdeaProjects\RuoYi-Vue-master\ruoyi-system\target\classes\mapper\system\sm\hr\SmHrUserInfoMapper.xml] 
### The error may involve com.ruoyi.system.sm.hr.mapper.SmHrUserInfoMapper.insertSmHrUserInfo-Inline 
### The error occurred while setting parameters 
### SQL: insert into sm_hr_user_info 
( employee_code, employee_name, ministerial_dept_id, division_dept_id, post_id, manager_level_id, entry_date, password, depart_reason ) 
values ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
### Cause: java.sql.SQLIntegrityConstraintViolationException: 
Duplicate entry '0100323' for key 'sm_hr_user_info_u1' ; 
Duplicate entry '0100323' for key 'sm_hr_user_info_u1'; 
nested exception is java.sql.SQLIntegrityConstraintViolationException: 
Duplicate entry '0100323' for key 'sm_hr_user_info_u1'

即插入了一条记录,它的主键已存在,可以在后端进行判断。在SQL查询时记得要以主键为条件。

接口404异常

Uncaught (in promise) Error: Request failed with status code 404

情况一:
1、检查前端的路径和后端是否对得上
2、如果有参数传递,特别是字符串类型的,确保里面不包含’/'不然会被识别成路径
3、定位错误时,记得看F12中console或者network中的输出,根据输出判断前端是否发送请求以及请求的路径是否有问题
4、在后端“.”和“|”都是转义字符,必须得加"//";
情况二:
在自动生成代码之后,加入对应的文件,刷新页面发现404,后端打断点发现无法跳转:可能是忘了build了,后端记得build一下。

Uncaught (in promise) Error: 操作失败

1、打开network看能否发送请求
2、若能则查看后端
3、查看sql语句(我这里的问题是sql写错了)

验证规则出现问题

Invalid prop: type check failed for prop "rules". Expected Object, got String with value "rules".

这里是验证规则rules出现的问题,需要在rules前面加冒号。

SQL查询抛出异常

1、查询的参数不能为null,不然报错,结果为null不会

导入时报错

index.vue?9967:772 Uncaught TypeError: Cannot read property '0' of null

1、先下载模板,注意导入时的excel的开头部分需要与模板的相同。

因为span引起的错误

Invalid prop: type check failed for prop "span". 
Expected Number with value 15, got String with value "15".

在span前加上冒号即可

如何将el-form-item的label替换为图片

<el-form-item prop="range1">
    <span slot="label">
        <el-image :src="require(`@/assets/images/range1.png`)"></el-image>
    </span>
</el-form-item>

这样的话原来的label处就是图片了。

含Redis的报错

Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: 
Command timed out after 10 second(s)

重启Redis服务即可。

表格中删除操作的问题

Request method 'DELETE' not supported

1、后端打断点,发现无法跳转至后端,但是前端发送了请求
1、检查前端时,发现无法获得行信息,导致请求发送时没有行id,所以无法与后端对应
2、检查scope.row,发现没有id,再检查发现是后端查数据的时候sql语句没有传输id过来导致这里取不到

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值