在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>

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

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

常见字符转义:
在这里插入图片描述
注: 此文章只为记录开发过程中的错误,学习,如发现侵权请私信删除

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 在XML文件,特殊字符"&"需要使用转义符进行转义。根据引用\[1\],XML实体不允许出现"&","<",">"等特殊字符,否则会导致XML语法检查错误。因此,如果需要在XML文件包含这些字符,需要将它们分别写成"&amp;","&lt;","&gt;"再写入文件。在读取XML文件时,解析器会自动将转义符转换回原始的特殊字符,如引用\[2\]所述。需要注意的是,转义序列各字符间不能有空格,转义序列必须以";"结束,单独的"&"不被认为是转义开始,同时还要区分大小写。一个正确的示例可以是<Event> <!-- column --> <Attribute name="logid" type="string" coment="logid &amp; qid" /> </Event> \[3\]。 #### 引用[.reference_title] - *1* *2* [XML常用转义符](https://blog.csdn.net/qq_34129814/article/details/79104732)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [XML格式文件 & (与) / Map, String> 解析转义失败解决办法](https://blog.csdn.net/qq_39285950/article/details/129269258)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值