在xml文件中配置连接数据库条件连接符&转义

当我们使用xml配置文件配置连接数据库运行时可能会报一些警告:

Tue Jun 02 10:40:19 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Tue Jun 02 10:40:19 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Tue Jun 02 10:40:19 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

此警告并不影响程序的正常运行,但是有警告大家总会心痒痒的能解决的便解决。在配置数据库连接的时候在后面加useSSL=false便可以解决此警告。但是经常需要配置的不止一个数据,便需要使用&符号

问题:在配置xml文件直接使用&符号会报错

    <!-- 配置输入源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!-- 连接数据库的必备信息 -->
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql:///eesy?characterEncoding=utf8&useSSL=false"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
    </bean>

此时使用的&需要转义,将“ & ”转义为" &;"(注意:这里的分号要用英文格式,文章此处使用了中文格式建议手写改为英文格式),正确写法:

<property name="jdbcUrl" value="jdbc:mysql:///eesy?characterEncoding=utf8&useSSL=false"></property>

常见字符转义:
在xml文件中配置连接数据库条件连接符&转义_第1张图片
注: 此文章只为记录开发过程中的错误,学习,如发现侵权请私信删除

你可能感兴趣的:(在xml文件中配置连接数据库条件连接符&转义)