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

简介: <?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生成代码即可,发现没有中文乱码了。


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
SQL Java 数据库连接
【YashanDB知识库】解决mybatis的mapper文件sql语句结尾加分号";"报错
【YashanDB知识库】解决mybatis的mapper文件sql语句结尾加分号";"报错
|
SQL XML Java
MyBatis Mapper中使用limit参数的查询问题
总结而言,MyBatis中使用 `limit`参数的查询可以高度定制并且灵活,基于方法签名和XML映射文件的组合来达成多样化的查询需求。通过参数化查询和动态SQL,MyBatis可以有效地处理各种复杂情境下的数据库操作,并且将SQL语句的维护与业务代码的编写相分离,提升代码的可维护性和可阅读性。
1020 13
|
SQL Java 数据库连接
【YashanDB 知识库】解决 mybatis 的 mapper 文件 sql 语句结尾加分号";"报错
【YashanDB 知识库】解决 mybatis 的 mapper 文件 sql 语句结尾加分号";"报错
|
SQL Java 数据库连接
【潜意识Java】深入理解MyBatis的Mapper层,以及让数据访问更高效的详细分析
深入理解MyBatis的Mapper层,以及让数据访问更高效的详细分析
3514 1
|
SQL Java 数据库连接
Mybatis系列之 Error parsing SQL Mapper Configuration. Could not find resource com/zyz/mybatis/mapper/
文章讲述了在使用Mybatis时遇到的资源文件找不到的问题,并提供了通过修改Maven配置来解决资源文件编译到target目录下的方法。
Mybatis系列之 Error parsing SQL Mapper Configuration. Could not find resource com/zyz/mybatis/mapper/
|
SQL Java 数据库连接
mybatis使用四:dao接口参数与mapper 接口中SQL的对应和对应方式的总结,MyBatis的parameterType传入参数类型
这篇文章是关于MyBatis中DAO接口参数与Mapper接口中SQL的对应关系,以及如何使用parameterType传入参数类型的详细总结。
816 10
|
SQL XML Java
mybatis :sqlmapconfig.xml配置 ++++Mapper XML 文件(sql/insert/delete/update/select)(增删改查)用法
当然,这些仅是MyBatis功能的初步介绍。MyBatis还提供了高级特性,如动态SQL、类型处理器、插件等,可以进一步提供对数据库交互的强大支持和灵活性。希望上述内容对您理解MyBatis的基本操作有所帮助。在实际使用中,您可能还需要根据具体的业务要求调整和优化SQL语句和配置。
566 1
自定义SQL,可以利用MyBatisPlus的Wrapper来构建复杂的Where条件,如何自定义SQL呢?利用MyBatisPlus的Wrapper来构建Wh,在mapper方法参数中用Param注
自定义SQL,可以利用MyBatisPlus的Wrapper来构建复杂的Where条件,如何自定义SQL呢?利用MyBatisPlus的Wrapper来构建Wh,在mapper方法参数中用Param注
|
XML Java 数据库连接
Mybatis逆向工程的2种方法,一键高效快速生成Pojo、Mapper、XML,摆脱大量重复开发
【5月更文挑战第10天】Mybatis逆向工程的2种方法,一键高效快速生成Pojo、Mapper、XML,摆脱大量重复开发
587 6
|
XML Java 数据库连接
探秘MyBatis:手写Mapper代理的源码解析与实现
探秘MyBatis:手写Mapper代理的源码解析与实现
261 1