09-MySQL数据库连接配置文件

方式一:db.properties配置文件

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username=root
password=123456

导入db.properties配置文件

  • 在mybatis配置文件中引入
<properties resource="db.properties"/>
  • 在applicationContext.xml中引入
<context:property-placeholder location="classpath:database.properties"/>

引入之后再通过${}绑定

<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>

方式二:直接写

<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test?useSSL=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>

猜你喜欢

转载自blog.csdn.net/rookie__zhou/article/details/108741445