Eclipse、Maven、MyBatis自动生成代码、整合基本的SSM框架

代码自动生成
用的是装载插件的方式生成
在这里插入图片描述

在这里插入图片描述在这里插入图片描述
安装成功后,需要重启eclipse

使用自动生成代码需要
数据库有货 、插件要装、生成的目录要设置
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>
   <context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
       <property name="beginningDelimiter" value="`"/>
       <property name="endingDelimiter" value="`"/>
       <property name="javaFileEncoding" value="UTF-8"/>
       <!-- 为模型生成序列化方法-->
       <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
       <!-- 为生成的Java模型创建一个toString方法 -->
       <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
        <!-- 生成 mapper.xml时不 merge 直接覆盖原文件 -->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
       <commentGenerator>
           <!-- 是否去除自动生成的注释 true:是 : false:-->
           <property name="suppressAllComments" value="true"/>
       </commentGenerator>

       <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                       connectionURL="jdbc:mysql://localhost:3306/hospital2?useUnicode=true&amp;characterEncoding=utf8"
                       userId="root"
                       password="1234qwer">
           <!--防止生成其他库同名表-->
           <property name="nullCatalogMeansCurrent" value="true" />
       </jdbcConnection>
       
       <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 
			NUMERIC 类型解析为java.math.BigDecimal -->
       <javaTypeResolver>
			<property name="forceBigDecimals" value="true" />
		</javaTypeResolver>

       <!-- 生成 Entity 类存放位置,需要指明所在的包名,所在的项目地址:地址为本地的绝对路径,到项目的java目录 -->
       <javaModelGenerator targetPackage="com.management.hospital.entity" targetProject="hospital/src/main/java"/>
       <!-- 生成映射xml文件存放位置 -->
       <sqlMapGenerator targetPackage="mapper.xml" targetProject="hospital/src/main/resources"/>
       <!-- 生成 Dao 类存放位置 -->
       <javaClientGenerator type="XMLMAPPER" targetPackage="com.management.hospital.mapper" targetProject="hospital/src/main/java"/>

       <!-- 指定要生成的表名 -->
       <!-- <table tableName="ware" domainObjectName="Ware"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        
         <table tableName="outbound" domainObjectName="Outbound"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table> -->
        
         <table tableName="material" domainObjectName="Material"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
   </context>
</generatorConfiguration>

在这里插入图片描述
生成代码结构如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值