The content of element type "context" must match "(property*,plugin*,commentGenerator与自动生成代码

最近项目用SSM框架,在利用mybatis generator反向生成数据库对应的model实体时,报如下错误:

The content of element type "context" must match 

 "(property*,plugin*,commentGenerator?,jdbcConnection,javaTypeResolver?,javaModelGenerator,sqlMapGenerator?,javaClientGenerator?,table+)".


原因:

配置文件 generatorConfig.xml 里面的context的子元素必须按照它给出的顺序,如错误提示的match“……”部分。 当然也可能是你xml文件有错(这个容易检查出来)

MyBatis属于一种半自动的ORM框架,需要程序员自己编写sql语句。但是由于手写映射文件很容易错,mybatis官方提供逆向工程可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mapper.xml、po…)。

首先,创建数据库表basictype

CREATE TABLE `basictype` (
  `id` varchar(32) NOT NULL COMMENT '主键',
  `name` varchar(50) DEFAULT NULL COMMENT '名称',
  `created_date` datetime DEFAULT NULL COMMENT '创建时间',
  `modified_date` datetime DEFAULT NULL COMMENT '修改时间',
  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
  `isDelete` int(2) DEFAULT NULL COMMENT '是否可用(0:可用;1:不可用)',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='家具大类(物料大类:电器、
厨具、床具)';

下载mybatis-generator-core,配置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 >
<!--数据库的jdbc驱动的jar包地址-->
	<classPathEntry location="E:/mysql-connector-java-5.1.7.jar" />
	
 	<context id="MySqlTables" targetRuntime="MyBatis3">      
	  	<commentGenerator>
			<!--是否去除自动生成的注释 true:是; false:否-->
			<property name="suppressAllComments" value="false" />
		</commentGenerator>
		<!--数据库连接信息:驱动类、链接地址、用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
				connectionURL="jdbc:mysql://localhost:3306/mobile?characterEncoding=utf-8"
				userId="root" password="password">
		</jdbcConnection>		
		<javaTypeResolver>
 
                 <!--类型解析器-->
                 <!-- 默认false,把jdbc decimal 和 numeric 类型解析为integer -->
	         <!-- true,把jdbc decimal 和 numeric 类型解析为java.math.bigdecimal-->
			<property name="forceBigDecimals" value="false" /> 
		</javaTypeResolver>
		
		<!-- 生成模型的包名和位置-->
		<javaModelGenerator targetPackage="com.entity"
				targetProject="src">
			<!-- 是否让schema作为包后缀-->	
			<property name="enableSubPackages" value="true" />
			<!-- 从数据库返回的值被清理前后的空格-->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- 生成Dao接口的包名和位置-->
	    <javaClientGenerator type="XMLMAPPER"
				targetPackage="com.mapper" 
				targetProject="src">
			<property name="enableSubPackages" value="true"/>
		</javaClientGenerator>
		<!-- 生成映射文件xml的包名和位置-->	
	    <sqlMapGenerator targetPackage="com.mapperxml"
				targetProject="src">
				<!-- 是否让schema作为包后缀-->	
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>				
		 <!-- 用于自动生成代码的数据库表;生成哪些表-->
		 <table tableName="basictype">
		    <generatedKey column="id" sqlStatement="MySql" identity="true"/>
		</table>				
	</context>
</generatorConfiguration>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值