mybatis-generator生成通用mapper中文乱码解决

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-co

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
 
	<classPathEntry location="C:\Users\Administrator\Desktop\tools\generator\mysql-connector-java-5.1.34.jar" />
	<context id="DB2Tables" targetRuntime="MyBatis3Simple" defaultModelType="flat">
	 
		<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
			<property name="mappers" value="tk.mybatis.mapper.common.Mapper" />
			<!-- caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true -->
			<!-- <property name="caseSensitive" value="true" /> -->
		</plugin>
	
        <!-- 阻止生成自动注释 -->
        <commentGenerator>
        	
            <property name="suppressAllComments" value="true" />
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        
 
<property name="javaFileEncoding" value="UTF-8"/>

 
 
         <!-- 数据库连接信息 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/webchat" userId="root" password="root">
        </jdbcConnection>
        
        <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
         
        <javaModelGenerator targetPackage="webchat.model" targetProject="D:\workspace\webchat\src\main\java">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
        </javaModelGenerator>
         
        <sqlMapGenerator targetPackage="webchat.mapping" targetProject="D:\workspace\webchat\src\main\java">
                <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
         
        <javaClientGenerator type="XMLMAPPER" targetPackage="webchat.dao" targetProject="D:\workspace\webchat\src\main\java">
                <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
	 
	    
	<table tableName="t_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    
	<table tableName="t_group" domainObjectName="Group" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    <table tableName="group_user" domainObjectName="groupUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    
    <table tableName="group_message" domainObjectName="groupMessage" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    
    <table tableName="friend_type" domainObjectName="friendType" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    
    <table tableName="friend_message" domainObjectName="friendMessage" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
    
    <table tableName="friend" domainObjectName="Friend" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <generatedKey column="id" sqlStatement="Mysql"/>
    </table>
 

    
    
	</context>
</generatorConfiguration>

首先检查你的 generator.xml  要有  <property name="javaFileEncoding" value="UTF-8"/>


然后检查工程是否为utf-8编码!


最后打开你的exlipse.ini 文件,最末尾加上 -Dfile.encoding=UTF-8


重启eclipse,配置maven生成代码即可,发现没有中文乱码了。


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
SQL XML Java
mybatis Mapper的概念与实战
MyBatis 是一个流行的 Java 持久层框架,它提供了对象关系映射(ORM)的功能,使得Java对象和数据库中的表之间的映射变得简单。在MyBatis中,Mapper是一个核心的概念,它定义了映射到数据库操作的接口。简而言之,Mapper 是一个接口,MyBatis 通过这个接口与XML映射文件或者注解绑定,以实现对数据库的操作。
42 1
|
3月前
|
Java 数据库连接 Maven
使用mybatis插件generator生成实体类,dao层和mapper映射
使用mybatis插件generator生成实体类,dao层和mapper映射
61 0
|
7月前
|
SQL Java 数据库连接
Mybatis知识【Mapper代理开发&核心配置】第三章
Mybatis知识【Mapper代理开发&核心配置】第三章
|
8月前
|
SQL XML Java
Mybatis的mapper接口实现原理
Mybatis的mapper接口实现原理
135 0
|
9月前
|
XML Java 数据库连接
Mybatis使用generator逆向工程生成器生成entity、mapper、.xml模版类
今天将表建好了,但是一个一个的建实体类、Mapper接口、Mapper.xml文件就十分的麻烦,所以我就想到了MyBatis逆向,今天就操作一把!这里我们采用maven来进行操作。
139 0
|
4月前
|
SQL Java 数据库连接
Mybatis之Mybatis简介、搭建Mybatis相关步骤(开发环境、maven、核心配置文件、mapper接口、映射文件、junit测试、log4j日志)
【1月更文挑战第2天】 MyBatis最初是Apache的一个开源项目iBatis, 2010年6月这个项目由Apache Software Foundation迁移到了Google Code。随着开发团队转投Google Code旗下,iBatis3.x正式更名为MyBatis。代码于2013年11月迁移到Github iBatis一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架。iBatis提供的持久层框架包括SQL Maps和Data Access Objects(DAO)
208 3
Mybatis之Mybatis简介、搭建Mybatis相关步骤(开发环境、maven、核心配置文件、mapper接口、映射文件、junit测试、log4j日志)
|
1月前
|
SQL Java 数据库连接
MyBatis精髓揭秘:Mapper代理实现的黑盒探索
MyBatis精髓揭秘:Mapper代理实现的黑盒探索
23 1
|
2月前
|
XML SQL Java
Mybatis接口Mapper内的方法为啥不能重载吗
Mybatis接口Mapper内的方法为啥不能重载吗
23 0
|
2月前
|
Java 数据库连接 mybatis
在SpringBoot集成下,Mybatis的mapper代理对象究竟是如何生成的
在SpringBoot集成下,Mybatis的mapper代理对象究竟是如何生成的
22 0