1. 程式人生 > 其它 >SQL Server日期格式的轉換

SQL Server日期格式的轉換

新建 maven 工程

  <build>
    <plugins>
      <!--mybatis程式碼自動生成外掛-->
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.6</version>
        <dependencies>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
          </dependency>
        </dependencies>
        <configuration>
          <!--配置檔案的位置-->
          <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
          <verbose>true</verbose>
          <overwrite>true</overwrite>
        </configuration>
      </plugin>
    </plugins>
  </build>

resources 目錄下建立 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="mysqlGenerator" targetRuntime="MyBatis3Simple">
    <!-- 序列化外掛 -->
    <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
    <!-- toString 外掛,生成toString 方法 -->
    <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
    <commentGenerator>
      <property name="suppressDate" value="true"/>
      <!-- 是否去除自動生成的註釋 true:是 : false:否 -->
      <property name="suppressAllComments" value="true"/>
    </commentGenerator>

    <!-- mysql 驅動 5.1.45 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                    connectionURL="jdbc:mysql:///ylb"
                    userId="root"
                    password="root"/>

    <javaModelGenerator targetPackage="com.bjpowernode.ylb.entity" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>

    <!--生成對映檔案存放位置-->
    <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
      <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>

    <javaClientGenerator targetPackage="com.bjpowernode.ylb.mapper" type="XMLMAPPER" targetProject="src/main/java">
      <!-- 在targetPackage的基礎上,根據資料庫的schema再生成一層package,最終生成的類放在這個package下,預設為false -->
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>

    <!-- 資料庫表名及對應的Java模型類名 -->
    <table tableName="b_product_info" domainObjectName="ProductEntity"
           enableCountByExample="false"
           enableUpdateByExample="false"
           enableDeleteByExample="false"
           enableSelectByExample="false"
           enableSelectByPrimaryKey="false"
           enableUpdateByPrimaryKey="false"
           enableDeleteByPrimaryKey="false"
           selectByPrimaryKeyQueryId="false"
           selectByExampleQueryId="false"
    />

    <table tableName="b_bid_info" domainObjectName="BidEntity"/>
    <table tableName="b_income_record" domainObjectName="IncomeEntity"/>
    <table tableName="b_recharge_record" domainObjectName="RechargeEntity"/>
    <table tableName="u_user" domainObjectName="UserEntity"/>
    <table tableName="u_finance_account" domainObjectName="AccountEntity"/>
  </context>
</generatorConfiguration>

可選引數,預設都是true,會自動生成增刪改查,就弄成預設的即可。如果改為 false,有可能不會自動生成 ResultMap

     enableCountByExample="false"
     enableUpdateByExample="false"
     enableDeleteByExample="false"
     enableSelectByExample="false"
     enableSelectByPrimaryKey="false"
     enableUpdateByPrimaryKey="false"
     enableDeleteByPrimaryKey="false"
     selectByPrimaryKeyQueryId="false"
     selectByExampleQueryId="false"