mybatis generator 中文乱码|已解决

使用mybatis generator插件生成代码,中文注释出现乱码。解决方案如下:

尝试在context节点中加入编码属性。

generatorConfig.xml

<?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="mysql-connector-java-8.0.18.jar" /> -->
	<context id="MySQLTables" targetRuntime="MyBatis3">
		<property name="javaFileEncoding" value="UTF-8"/>
		<property name="fileEncoding" value="UTF-8"/>

<commentGenerator type="org.mybatis.generator.internal.DefaultCommentGenerator" >
			<property name="javaFileEncoding" value="UTF-8"/>
</commentGenerator>

若仍未能解决尝试以下操作:

For Eclipse

eclipse.ini

-Dfile.encoding=UTF-8

Restart Eclipse.

For MySQL

characterEncoding=utf-8

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/demo?allowPublicKeyRetrieval=true&amp;useSSL=false&amp;serverTimezone=UTC&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;" userId="root" password="pw" />