MyBatis GeneratorXML Configuration File Reference 1

本文介绍了MyBatis Generator的基本配置方法,通过一个XML配置文件示例,详细解释了如何设置数据库连接信息、生成对象的方式及对应表等内容。此外,还提供了关于文件中各个元素及其属性的具体说明。

http://mybatis.org/generator/configreference/xmlconfig.html

最常见用例中, MyBatis Generator (MBG) 靠XML配置文件来驱动。配置文件告诉MBG以下信息:

  • 如何连接数据库;
  • 需要产生哪些对象,以及怎么产生;
  • 用哪些表来产生对象。

下面是个MBG配置文件的例子,查看关于元素和属性值的更多信息,需要查阅单独的页面。

<?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="/Program Files/IBM/SQLLIB/java/db2java.zip" />

  <context id="DB2Tables" targetRuntime="MyBatis3">
    <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
        connectionURL="jdbc:db2:TEST"
        userId="db2admin"
        password="db2admin">
    </jdbcConnection>

    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <javaModelGenerator targetPackage="test.model" targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="test.xml"  targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

    <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  targetProject="\MBGTestProject\src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

    <table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
      <property name="useActualColumnNames" value="true"/>
      <generatedKey column="ID" sqlStatement="DB2" identity="true" />
      <columnOverride column="DATE_FIELD" property="startDate" />
      <ignoreColumn column="FRED" />
      <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
    </table>

  </context>
</generatorConfiguration>

一下是关于这个文件的重要提示:

  • 文件指定用来连接数据库的legacy DB2 CLI驱动,并且指定驱动的位置。
  • The Java Type Resolver should not force the use of BigDecimal fields - this means that integral types (Short, Integer, Long, etc.) will be substituted if possible. This feature is an attempt to make database DECIMAL and NUMERIC columns easier to deal with.
  • The Java model generator should use sub-packages. This means that the generated model objects will be placed in a package called test.model.db2admin in this case (because the table is in the DB2ADMIN schema). If the enableSubPackages attribute was set to false, then the package would be test.model. The Java model generator should also trim strings. This means that the setters for any String properties will call the trim function - this is useful if your database might return blank characters at the end of character columns.
  • The SQL Map generator should use sub-packages. This means that the generated XML files will be placed in a package called test.xml.db2admin in this case (because the table is in the DB2ADMIN schema). If the enableSubPackages attribute was set to false, then the package would be test.xml.
  • The DAO generator should use sub-packages. This means that the generated DAO classes will be placed in a package called test.dao.db2admin in this case (because the table is in the DB2ADMIN schema). If the enableSubPackages attribute was set to false, then the package would be test.dao. The DAO generator should generate mapper interfaces that reference an XML configuration for MyBatis.
  • The file specifies only one table will be introspected, but many more could be specified. Important notes about the specified table include:
    • The generated objects will be based on the name Customer (CustomerKey, Customer, CustomerMapper, etc.) - rather than on the table name.
    • Actual column names will be used as properties. If this property were set to false (or not specified), then MBG would attempt to camel case the column names. In either case, the name can be overridden by the <columnOverride> element
    • The column has a generated key, it is an identity column, and the database type is DB2. This will cause MBG to generate the proper <selectKey> element in the generated <insert> statement so that the newly generated key can be returned (using DB2 specific SQL).
    • The column DATE_FIELD will be mapped to a property called startDate. This will override the default property which would be DATE_FIELD in this case, or dateField if the useActualColumnNames property was set to false.
    • The column FRED will be ignored. No SQL will list the field, and no Java property will be generated.
    • The column LONG_VARCHAR_FIELD will be treated as a VARCHAR field, regardless of the actual data type.
【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)》的技术资源,聚焦于电力系统中低碳经济调度问题,结合N-1安全准则与分布鲁棒机会约束(DRCC)方法,提升调度模型在不确定性环境下的鲁棒性和可行性。该资源提供了完整的Matlab代码实现,涵盖建模、优化求解及仿真分析全过程,适用于复杂电力系统调度场景的科研复现与算法验证。文中还列举了大量相关领域的研究主题与代码资源,涉及智能优化算法、机器学习、电力系统管理、路径规划等多个方向,展示了广泛的科研应用支持能力。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事能源调度、智能电网相关工作的工程师。; 使用场景及目标:①复现高水平期刊(如EI/SCI)关于低碳经济调度的研究成果;②深入理解N-1安全约束与分布鲁棒优化在电力调度中的建模方法;③开展含新能源接入的电力系统不确定性优化研究;④为科研项目、论文撰写或工程应用提供可运行的算法原型和技术支撑。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码与案例数据,按照目录顺序逐步学习,并重点理解DRCC建模思想与Matlab/YALMIP/CPLEX等工具的集成使用方式,同时可参考文中列出的同类研究方向拓展研究思路。
内容概要:本文详细介绍了一个基于MATLAB实现的电力负荷预测项目,采用K近邻回归(KNN)算法进行建模。项目从背景意义出发,阐述了电力负荷预测在提升系统效率、优化能源配置、支撑智能电网和智慧城市建设等方面的重要作用。针对负荷预测中影响因素多样、时序性强、数据质量差等挑战,提出了包括特征工程、滑动窗口构造、数据清洗与标准化、K值与距离度量优化在内的系统性解决方案。模型架构涵盖数据采集、预处理、KNN回归原理、参数调优、性能评估及工程部署全流程,并支持多算法集成与可视化反馈。文中还提供了MATLAB环境下完整的代码实现流程,包括数据加载、归一化、样本划分、K值选择、模型训练预测、误差分析与结果可视化等关键步骤,增强了模型的可解释性与实用性。; 适合人群:具备一定MATLAB编程基础和机器学习基础知识,从事电力系统分析、能源管理、智能电网或相关领域研究的研发人员、工程师及高校师生;适合工作1-3年希望提升实际项目开发能力的技术人员; 使用场景及目标:①应用于短期电力负荷预测,辅助电网调度与发电计划制定;②作为教学案例帮助理解KNN回归在实际工程中的应用;③为新能源接入、需求响应、智慧能源系统提供数据支持;④搭建可解释性强、易于部署的轻量级预测模型原型; 阅读建议:建议结合MATLAB代码实践操作,重点关注特征构造、参数调优与结果可视化部分,深入理解KNN在时序数据中的适应性改进方法,并可进一步拓展至集成学习或多模型融合方向进行研究与优化。
MyBatis provides the `parameterMap` element as a way to map complex parameter objects to the SQL statement parameters. It is used when you have a complex object with multiple properties and you want to map them to the corresponding parameters in your SQL statement. To use the `parameterMap`, you need to define it in your MyBatis XML configuration file. Here's an example: ```xml <!-- Define the parameterMap --> <parameterMap id="myParameterMap" type="com.example.MyParameterObject"> <parameter property="param1" jdbcType="VARCHAR"/> <parameter property="param2" jdbcType="INTEGER"/> <!-- more parameters... --> </parameterMap> <!-- Use the parameterMap in your SQL statement --> <select id="myQuery" parameterMap="myParameterMap"> SELECT * FROM my_table WHERE column1 = #{param1} AND column2 = #{param2} <!-- more conditions... --> </select> ``` In the above example, `com.example.MyParameterObject` is a Java class representing the complex parameter object. The `parameterMap` element defines the mappings between the properties of `MyParameterObject` and the SQL statement parameters. Each `parameter` element specifies the property name and the corresponding JDBC type. You can then reference the `parameterMap` in your SQL statement using the `parameterMap` attribute of the statement. The `#{param1}` and `#{param2}` placeholders will be replaced with the values from the corresponding properties of the parameter object. Note that starting from MyBatis 3, it is recommended to use annotation-based parameter mapping (`@Param` annotation) or inline parameter mapping (`#{property}`) instead of `parameterMap` for simplicity and better readability.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值