Java开发问题收录

项目打包时出现: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

可能是安装了多版本maven,与系统指定的maven不一致 导致idea没有识别出新版本的maven(需要设置默认maven,并重启生效--是个坑), 以及设置maven的Runner(指定JDK版本,如果安装了多个的话).

APR版本不兼容 An incompatible version [1.1.33] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

目前Tomcat8以上推荐使用APR, 解决方法:升级该版本、或者关闭APR(Spring Boot 2以上好像会自动开启)

SH脚本换行符问题 $’\r’: command not found

打开vi使用set ff=unix

MyBatisPlus采坑 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

原因是没有扫描到自定的xml文件,debug发现MyBatisPlus默认扫描dao层同目录下的xml文件。解决方法有两种。
1. 是把xml文件复制到dao层同一目录下,MybatisPlus会自动扫描
2. mybatis-plus.mapper-locations=classpath*:/mapper/*.xml 指定扫描路径,注意:xml是放在resource下的,放在src下目测无效

MyBatis开启二级缓存报错

缺少包:        
<!--mybatis 启用ehcache 二级缓存-->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-ehcache</artifactId>
        <version>1.0.0</version>
    </dependency>

MyBatisPlus枚举类关联异常

问题描述:
真是诡异的一幕, 使用@Test时,一切枚举类相关的正常, 但应用启动后,访问controller调用service时, 出现枚举类关联失败,导致插入数据库的不是枚举状态值,而是字符串,导致插入失败.初步认为是MyBatisPlus3.0.7.1默认的枚举处理器有问题

解决方式: 
在properties或yml中配置mybatis-plus.configuration.default-enum-type-handler=org.apache.ibatis.type.EnumOrdinalTypeHandler  指定枚举类处理器
同时记得指定mybatis-plus.type-enums-package=com.***.enums

tip: 
1. 使用MyBatisPlus关联枚举类, 只需要加@EnumValue
2. MVC枚举类与状态码的转换, 只需要使用@JsonValue和@JsonCreator

完整枚举类样例:
```java
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.commons.collections.map.HashedMap;

import java.util.Map;

/**
 * @Author: laichengfeng
 * @Description: 账号状态
 * @Date: 2019/06/03 14:06
 */
public enum AccountStatus {
    NO_ACTIVE(0),
    NORMAL(1),
    FREEZE(2);
    @EnumValue
    private int code;
    AccountStatus(int code) {
        this.code = code;
    }
    public static final Map<Integer, AccountStatus> map = new HashedMap();
    static {
        for(AccountStatus status: values()) {
            map.put(status.getCode(), status);
        }
    }
    @JsonCreator
    public static AccountStatus of(int code) {
        return map.get(code);
    }
    @JsonValue
    public int getCode() {
        return code;
    }
}

```

git reset --hard xxx 之前没有git commit本地代码, 导致代码丢失, 血一样的教训 (有git add, 没有git coomit的情况, 可以恢复部分)

https://www.cnblogs.com/hope-markup/p/6683522.html

MyBatisPlus 使用默认的org.apache.ibatis.type.EnumOrdinalTypeHandler时, @Test可以正常处理枚举类, 但服务正常启动时无法处理(3.0.7.1)

处理方式: 将MP改成3.1.1版本, 然后添加mybatis-plus.configuration.default-enum-type-handler=com.baomidou.mybatisplus.extension.handlers.EnumTypeHandler

如果在mapper.xml中需要用到枚举类转换, 以如下方式写入
<update id="updateStatusAndPasswordById">
    update bal_user
    set status=#{status, typeHandler=com.baomidou.mybatisplus.extension.handlers.EnumTypeHandler}, password=#{password},
    <include refid="Base_Update_Time"/>
    where id=#{id}
</update>

springboot添加外部jar包及打包(外部jar在打包时没有添加进来的问题)

https://www.cnblogs.com/bbthome/p/9230030.html

springboot整合jsp导成jar包后无法访问html和jsp

https://blog.csdn.net/qq_26684469/article/details/81475432

Git实现多个远程仓库同步

git remote -v
git remote remove origin
git remote add origin xxx
git remote set-url --add origin xxx

RSA生成密钥对长度为1024和2048是有区别的 [javax.crypto.BadPaddingException: Decryption error]

出现javax.crypto.BadPaddingException: Decryption error异常时,请检查RSA对应密钥对的位数以及每次加解密长度
    1024位: 
        每次加密最大长度为117位
        每次解密最大长度为128位
    2048位:
        每次加解密最大长度都是256位

多模块使用Eureka服务发现时,出现无法引用远程服务的问题

检查引用远程服务的类是否在@EnableXXX类的子目录中

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ‘org.springframework.transaction.PlatformTransactionManager’ available: expected single matching bean but found 2: transactionManager,dataSourceTransactionManager

多配置了dataSource

Set转String[]报java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;

错误
Set<String> set = new HashSet<>();
String[] strsFalse = (String[]) set.toArray();

正确
String[] strsTrue = set.toArray(new String[set.size()]);

随机数生成(线程安全&高性能)

线程安全 性能 JDK版本
Random 线程安全 1.7之前
ThreadLocalRandom 线程安全 1.7及之后

猜你喜欢

转载自blog.csdn.net/qq_31281327/article/details/115228788