原因描述 :底层数据库错误,无法连接
使用工具idea
功能。配置mybatis文件。读取properties时,只有url无法读取到。其他的driver,username,password都可以读取。
各种方法找完都不管用。
原因:
在mybatis-config.xml文件中配置时,因为字符串转义问题,所以&号使用《&;》代替
但是在properties文件中,不会识别到<&;>,所以如果复制过去,再读取就会格式错误
db.properties文件中错误的示范
url=jdbc:mysql://localhost:3306/***?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/
总结:
不使用properties时,在mybatis-config.xml中写url,因为java转义问题,&号使用 &;代替
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test1?useSSL=false& useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
使用properties时,在properties文件中需要这样写,不要转义,正常写&连接
#url=jdbc:mysql://localhost:3306/test1?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull