开发问题记录

  1. saas系统,商户回调我们时对数据加密(用我们提供的公钥加密),我们回调接口用私钥解密解不开,报javax.crypto.BadPaddingException: Decryption error异常,确保密钥对没问题的情况下解不开?
    原因:双方RSA使用的provider不一致。我们这边使用默认的provider,jdk自带的com.sun.crypto.provider.SunJCE,而商户那边使用了org.bouncycastle.jce.provider.BouncyCastleProvider(BC)。加密解密必须使用相同的provider才能保证在秘钥对没问题的时候,加密解密成功。
 Cipher cipher = Cipher.getInstance("RSA"); //jdk默认provider
 Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm(),new BouncyCastleProvider());//BC provider
  1. Spring Boot Maven项目使用SystemPath引用第三方平台jar:ClassNotFoundException错误
	<dependency>
        <groupId>ftp4j</groupId>
        <artifactId>ftp4j</artifactId>
        <version>1.7.2</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/libs/ftp4j-1.7.2.jar</systemPath>
     </dependency>

解决方案:在build节点加入以下语句使包正确的导入

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
	    <!-- fork is enable,用于明确表示编译版本配置的可用 -->
	    <fork>true</fork>
	    <addResources>true</addResources>
	    <!--POM不是继承spring-boot-starter-parent的话,需要下面的指定-->
	    <mainClass>${start-class}</mainClass>
	   <!-- 解决systemPath jar打包时引入问题-->
	   <includeSystemScope>true</includeSystemScope>
	</configuration>
	<executions>
	    <execution>
	        <goals>
	            <goal>repackage</goal>
	        </goals>
	    </execution>
	</executions>
</plugin>

打war包用上面方法jar会生成在lib-provided目录下,再加下面这个插件可以解决


<!--解决systemPath 打war包时 systemPath jar的引入问题-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
    <webResources>
        <resource>
            <directory>${project.basedir}/src/main/resources/lib/</directory>
            <targetPath>WEB-INF/lib</targetPath>
            <includes>
                <include>**/*.jar</include>
            </includes>
        </resource>
    </webResources>
</configuration>
</plugin>  

一般都是使用call mvn install:install-file -Dfile=xx.jar -DgroupId=xx -DartifactId=xx -Dversion=xx -Dpackaging=jar 命令打到仓库,然后修改仓库里的pom的依赖,不建议使用systemPath,它只能打进当前的jar,不能将该jar的所需的依赖jar一起打包到lib

  1. 前端axios 发 post 请求时,后端接收不到参数的问题
    查阅 axios 文档可以知道:axios 使用 post 发送数据时,默认是直接把 json 放到请求体中提交到后端的,Content-Type 变成了application/json;charset=utf-8,这就与我们服务端要求的 Content-Type:application/x-www-form-urlencoded 以及 @RequestParam@ModelAttribute不符合
    解决方案:以表单的形式传(指定表单形式),避免使用默认的json格式
  2. 跨域问题

一般解决方案

@Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) {
        String originHeader = httpServletRequest.getHeader("Origin");
        httpServletResponse.setHeader("Access-Control-Allow-Origin", originHeader);
        httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
        //前端携带Credentials 这里不能设置为*
        httpServletResponse.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Orgin,XMLHttpRequest,Accept,Authorization,authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With");
       //需要注意的是,如果要发送Cookie,即前端Access-Control-Allow-Credentials设为true
       //那么Access-Control-Allow-Origin就不能设为星号,必须指定明确的、与请求网页一致的域名
        httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true");
        httpServletResponse.setHeader("Access-Control-Expose-Headers", "Accept-Ranges, Content-Encoding, Content-Length, Content-Range" + "," + "authorization");
        return true;
    }

springboot下解决方案

/*跨域问题 springboot*/
    @Bean
    public FilterRegistrationBean corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        config.setMaxAge(3600L);
        source.registerCorsConfiguration("/**", config);
        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
        bean.setOrder(1);
        return bean;
    }
  1. Boolean引起的空指针问题
 List<ApiLog> list = new ArrayList<>();
 ApiLog apiLog=new ApiLog();
 list.add(apiLog);
 List<ApiLog> result=list.stream().filter(l->l.getResult()).collect(toList());
 System.out.println(result);

ApiLog里有个字段 Boolean result;默认值为null(boolean 默认为false)
由于result值为null, 所以l.getResult()在运行的时候会抛出空指针异常
解决方案:将ApiLog里的result类型改为boolean
或者对getResult加个判断 List result=list.stream().filter(l->l.getResult()==null?false:l.getResult()).collect(toList());

  1. OSS根据文件名(objKey)下载 ,获取流的时候因为在Finally里执行了ossClient.shutdown(),返回的流为空流。finally是在return语句执行之后,返回之前执行的 返回流之前将ossClient shutdown会清空流
public static InputStream getOssInputStream(String objkey) {
        OSSClient ossClient = ossClientInitialization();
        try {
            OSSObject ossObject = ossClient.getObject(bucketName, objkey);
            if(ossObject!=null)
                return ossObject.getObjectContent();
            return null;
        } catch (Exception e){
            return null;
        }finally {
            //这处不能返回之前执行,会将流清空
            ossClientRelease(ossClient);
        }
    }

解决方案 将流和ossClient一起返回,关闭client由调用者来控制

 public static InputStreamRes getInputStreamRes(String objkey) {
        OSSClient ossClient = ossClientInitialization();
        try {
            OSSObject ossObject = ossClient.getObject(bucketName, objkey);
            if(ossObject!=null)
                return new InputStreamRes(ossObject.getObjectContent(),ossClient);
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
  1. springboot启动info日志: is not eligible for getting processed by all BeanPostProcessors
    原因:BeanPostProcessor是控制Bean初始化开始和初始化结束的接口。换句话说实现BeanPostProcessor的bean会在其他bean初始化之前完成,BeanPostProcessor会通过接口方法检查其他类型的Bean并做处理。当一个Bean不是被BeanFactory注册的所有BeanPostProcessor处理过则会打印上述信息。通常auto-proxy只是针对部分bean的进行处理的,所以个别bean不是被“完全”处理也很正常。
    解决方案:在此类中添加注解@Scope(proxyMode = ScopedProxyMode.INTERFACES)

  2. mybatis-plus 集成 pagehelper 冲突
    原因 :pagehelper中也依赖了mybatis和mybatis-spring,和mybatis-plus版本中的冲突。
    解决方案:排除pagehelper的依赖mybatis和mybatis-spring的jar包以免与mybatis-plus的冲突

 <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis-spring</artifactId>
                </exclusion>
            </exclusions>
  </dependency>
  1. Spring Security 使用@PreAuthorize 失效。
    1)配置类上开启 prePostEnabled = true@EnableGlobalMethodSecurity(prePostEnabled = true)
    2)角色权限要有前缀ROLE_

  2. vue eslint语法限制,控制台会报大量的错误
    在这里插入图片描述
    解决方案:关闭eslint语法检测=>找到config下的index.js 在index.js里找到useEslint:true 把true改为false

  3. mybatis if test 标签 问题

1)判断单个的字符要写到双引号里面才行
错误: <if test="type== 'Y' "> 
正确: <if test='type== "Y" '>或者<if test="type== 'Y'.toString() ">
原因:因为单引号内如果为单个字符时,OGNL将会识别为Java 中的 char类型,显然String 类型与char类型做==运算会返回false,从而导致表达式不成立
2)只有String类型才需要判断是否!='',其他类型完全没有这个必要
 例:<if test="type!= null and type!=' ' ">and type= #{type} </if> ,当type为Integer类型并且值为0时,if判断结果为false。
原因:如果对象是一个Number类型,值为0时将被解析为false,否则为true,浮点型0.00也是如此。OGNL对于boolean的定义和JavaScript有点像,即'' == 0 == false。
  1. vue table 行内编辑,通过v-show 使input(修改)和span(展示)切换,下文show是个数组
    坑点 1:v-show中的值改变,但视图不刷新问题
    坑点2:ref动态绑定获取input焦点失效
<el-table-column prop="remark" label="持有(可编辑)" sortable align="center">
                    <template slot-scope="scope">
                        <el-input
                            :ref="'input'+scope.$index"
                            placeholder="请输入内容"
                            v-show="show[scope.$index]"
                            v-model="scope.row.remark"
                            @blur="handleEdit(scope.$index, scope.row)"
                        ></el-input>
                        <span
                            v-show="!show[scope.$index]"
                            @click="toEdit(scope.$index)"
                        >{{scope.row.remark}}</span>
                    </template>
     </el-table-column>
 		//修改数据
        handleEdit(index, row) {
            this.$post('/fund/edit', { id: row.id, remark: row.remark }, true).then(res => {
                if (res.code == 200) {
                    //直接赋值视图不刷新
                    this.$set(this.show, index, false);
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        //跳到编辑
        toEdit(index) {
            let input = 'input' + index;
            //ref不是响应式的 必须要定时器
            setTimeout(() => {
                this.$nextTick(() => {
                    //获取焦点
                    this.$refs[input].focus();
                });
            }, 10);

            //直接赋值视图不刷新
            this.$set(this.show, index, true);
        },

坑点1: 根据官方文档定义:如果在实例创建之后添加新的属性到实例上,它不会触发视图更新。也就是说当vue的data里边声明或者已经赋值过的对象或者数组(数组里边的值是对象)时,向对象中添加新的属性,如果更新此属性的值,是不会更新视图的。
简单粗暴的解决方案:在给对象添加属性时采用:this.$set(this.obj,属性名,属性值)
坑点2: ref不是响应式的,所有的动态加载的模板更新它都无法相应的变化。
 解决方案:可以通过setTimeOut(()=>{…},0)来实现

  1. el-select 1.数据回显问题 2.选项无法选择的问题
    解决方案:
    1 . 数据类型要一致,下拉选中的key是number,回显的时候如果传的是字符串类型则无法正常回显。parseInt进行转换下
    2 .加个@change="selectChange"事件,selectChange 中方法加this.$forceUpdate();
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值