欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mybatis 使用jdbc.properties文件设置不起作用的解决方法

程序员文章站 2023-01-15 09:39:58
这样写的时候起作用:

这样写的时候起作用:

<?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"> 
<configuration> 
 <typealiases> 
  <typealias type="com.hc.entity.userinfo" alias="userinfo"/> 
 </typealiases> 
 <environments default="development"> 
  <environment id="mysql"> 
   <transactionmanager type="jdbc"/> 
   <datasource type="pooled"> 
    <property name="driver" value="com.mysql.jdbc.driver"/> 
    <property name="url" value="jdbc:mysql://localhost:3306/db_mybatis"/> 
    <property name="username" value="hhc"/> 
    <property name="password" value="******"/> 
   </datasource> 
  </environment> 
 </environments> 
 <mappers> 
  <mapper resource="com/hc/mapper/userinfo.xml"/> 
 </mappers> 
</configuration> 

这样写不起作用:

jdbc.driverclass=com.mysql.jdbc.driver 
jdbc.url=jdbc:mysql://localhost:3306/db_mybatis 
jdbc.username=hc 
jdbc.password=123456 

<?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"> 
<configuration> 
 <properties resource="jdbc.properties"/> 
 <typealiases> 
  <typealias type="com.hc.entity.userinfo" alias="userinfo"/> 
 </typealiases> 
 <environments default="development"> 
  <environment id="mysql"> 
   <transactionmanager type="jdbc"></transactionmanager> 
   <datasource type="pooled"> 
    <property name="driver" value="${jdbc.driverclass}"/> 
    <property name="url" value="${jdbc.url}"/> 
    <property name="username" value="${jdbc.username}"/> 
    <property name="password" value="${jdbc.password}"/> 
   </datasource> 
  </environment> 
 </environments> 
 <mappers> 
  <mapper resource="com/hc/mapper/userinfo.xml"/> 
 </mappers> 
</configuration> 

解决方法:

    1.在jdbc.properties鼠标右键properties(属性),把iso-8859-1更改为utf-8

    2.在整个项目鼠标右键,把iso-8859-1更改为utf-8   具体操作如下图

mybatis 使用jdbc.properties文件设置不起作用的解决方法

总结

以上所述是小编给大家介绍的mybatis 使用jdbc.properties文件设置不起作用的解决方法,希望对大家有所帮助