文章目录
JeecgBoot开发问题记录
一、JeecgBoot下拉搜索多选失败:报Sign签名校验失败
1.报错信息:
传递中文时,解码前后不一致导致验证失败
[http-nio-8080-exec-9] ERROR o.j.config.sign.interceptor.SignAuthInterceptor:62 - request URI = /jeecg-boot/sys/dict/getDictItems/report_factory,factory,factory,%20report%20%3D%20'%E4%BA%A7%E9%94%80%E5%AD%98'
[http-nio-8080-exec-9] ERROR o.j.config.sign.interceptor.SignAuthInterceptor:63 - Sign 签名校验失败!Header Sign : D84990622B0106819CB55D43238A10D6
2.修改内容:
-
1.修改Java文件目录:
jeecg-boot\jeecg-boot-base\jeecg-boot-base-core\src\main\java\org\jeecg\config\sign\util\SignUtil.java
-
2.修改getParamsSign类:
-
修改前:
/**
* @param params
* 所有的请求参数都会在这里进行排序加密
* @return 得到签名
*/
public static String getParamsSign(SortedMap<String, String> params) {
//去掉 Url 里的时间戳
params.remove("_t");
String paramsJsonStr = JSONObject.toJSONString(params);
log.info("Param paramsJsonStr : {}", paramsJsonStr);
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
String signatureSecret = staticConfig.getSignatureSecret();
if(oConvertUtils.isEmpty(signatureSecret) || signatureSecret.contains("${")){
throw new JeecgBootException("签名密钥 ${jeecg.signatureSecret} 缺少配置 !!");
}
//修改前
return DigestUtils.md5DigestAsHex((paramsJsonStr + signatureSecret).getBytes()).toUpperCase();
}
- 修改后
/**
* @param params
* 所有的请求参数都会在这里进行排序加密
* @return 得到签名
*/
public static String getParamsSign(SortedMap<String, String> params) {
//去掉 Url 里的时间戳
params.remove("_t");
String paramsJsonStr = JSONObject.toJSONString(params);
log.info("Param paramsJsonStr : {}", paramsJsonStr);
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
String signatureSecret = staticConfig.getSignatureSecret();
if(oConvertUtils.isEmpty(signatureSecret) || signatureSecret.contains("${")){
throw new JeecgBootException("签名密钥 ${jeecg.signatureSecret} 缺少配置 !!");
}
//修改后
byte[] bytes = StrUtil.bytes((paramsJsonStr + signatureSecret), "UTF-8");
return DigestUtils.md5DigestAsHex(bytes).toUpperCase();
}
二、Online表单生成代码失败处理
1.问题提醒:
:::::: 生成失败ERROR提醒 ::::::
1.未找到代码生成器模板,请确认路径是否含有中文或特殊字符!
2.如果是JAR包运行,请参考此文档 http://doc.jeecg.com/2043922
2.问题分析:
首先检查保存代码路径是否存在中文或特殊符号,如果存在则修改保存路径。
其次如果还不行的话,可能就是因为是使用jar启动项目,导致在生成代码的时候没有找到对应的模板。
[root@zxy jar]# ls
jeecg-boot-module-system-2.4.6.jar jeecg-boot-start.sh nohup.out
3.处理方法:
3.1. 在jar包所在同级文件夹创建config文件夹
[root@zxy jar]# mkdir config
[root@zxy jar]# ls
config jeecg-boot-module-system-2.4.6.jar jeecg-boot-start.sh nohup.out
3.2.将项目文件夹如下目录的文件拷贝到config目录下
[root@zxy jeecg]# ls
code-template code-template-online jeecg_config.properties jeecg_database.properties
[root@zxy jeecg]# pwd
/zxy/apps/project/jeecg-boot/jar/config/jeecg
3.3.重启jar包
三、测试接口异常Parameter ‘lists’ not found. Available parameters are [names, param1]
1.错误提示
根据提示可以简单看出是Parameter “lists” not found,而在我这个接口开发中,传到Mapper层的是一个list列表,而Mapper中已经使用了@Params(“names”)设置键。
{
"success": false,
"message": "操作失败,nested exception is org.apache.ibatis.binding.BindingException: Parameter 'lists' not found. Available parameters are [names, param1]",
"code": 500,
"result": null,
"timestamp": 1668177771433
}
2.排查解决
根据排查因为我已经在入参的时候通过@param绑定了,所以这里的collection也就不能写"lists",因为collection的值需要与@param绑定的参数名一致。
AccountController.java
@AutoLog(value = "测试-批量删除")
@ApiOperation(value="测试-批量删除", notes="测试-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="names",required=true) String names) {
accountService.removeByNames(Arrays.asList(names.split(",")));
return Result.OK("批量删除成功!");
}
AccountMapper.java
removeByNames(@Param("names") List<String> names)
AccountMapper.xml
<!--批量删除-->
<delete id="removeByNames" parameterType="List">
delete from account where name in
<foreach collection="lists" item="names" open="(" separator="," close=")">
#{names}
</foreach>
</delete>
因为在mapper里已经绑定了"names",所以将AccountMapper.xml中批量删除语句中的collection值做修改
<!--批量删除-->
<delete id="removeByNames" parameterType="List">
delete from account where name in
<foreach collection="names" item="names" open="(" separator="," close=")">
#{names}
</foreach>
</delete>
再次测试已经成功