当前位置: 移动技术网 > IT编程>开发语言>Java > mybatis 使用jdbc.properties文件设置不起作用的解决方法

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

2019年07月19日  | 移动技术网IT编程  | 我要评论

这样写的时候起作用:

<?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文件设置不起作用的解决方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网