When configuring url in xml file, "&" character causes parsing error

Learning mybatis mysql configuration information SqlMapConfig.xml configuration file, the configuration using the url attribute, operator error, need  & amp;  instead of

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- mybatis的主配置文件 -->
<configuration>
    <!-- 配置环境 -->
    <environments default="mysql">
        <!-- 配置mysql的环境-->
        <environment id="mysql">
            <!-- 配置事务的类型-->
            <transactionManager type="JDBC"></transactionManager>
            <!-- 配置数据源(连接池) -->
            <dataSource type="POOLED">
                <!-- 配置连接数据库的4个基本信息 -->
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/tunnel?useSSL=false&amp;characterEncoding=UTF-8"/>
                <property name="username" value="root"/>
                <property name="password" value="admin"/>
            </dataSource>
        </environment>
    </environments>

    <!-- 指定映射配置文件的位置,映射配置文件指的是每个dao独立的配置文件 -->
    <mappers>
        <mapper resource="com/bridge/dao/IUserDao.xml"/>
    </mappers>
</configuration>

<property name="url" value="jdbc:mysql://localhost:3306/tunnel?useSSL=false&characterEncoding=UTF-8"/>

Special characters such as "&" and "<" are directly placed in XML elements, which will cause XML file parsing errors. The above statement uses the ampersand "&", such XML will produce parsing errors. In order to avoid such errors, the professional argument is to use entity references of these special characters instead. There are also greater than signs, single quotes and double quotes. These 3 special characters can exist in XML and will not cause parsing errors, but they are replaced with entity references ">", "'", "" "Is a more standard grammar.

 The following are five entities predefined in XML documents
<less than ~~~~&t;
> greater than ~~~~>
& and ~~~~&
'single quote ~~~~'
"double Quotation marks ~~~~"


Study notes, reference:

 https://blog.csdn.net/qq_43251098/article/details/100562484

https://blog.csdn.net/zuke123456/article/details/6097923

 

 

Guess you like

Origin blog.csdn.net/qq_37552636/article/details/109645081
Recommended