Mybatis基于XML配置SQL映射器(一)

Durid和Mybatis开发环境搭建

SpringBoot搭建基于Spring+SpringMvc+Mybatis的REST服务(http://www.cnblogs.com/nbfujx/p/7694768.html

Mybatis之代码生成器

Maven Plugin管理

  <build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

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> <!-- !!!! Driver Class Path !!!! -->
<classPathEntry location="C:\Users\Han\.m2\repository\mysql\mysql-connector-java\5.1.35\mysql-connector-java-5.1.35.jar"/> <context id="context" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="false"/>
<property name="suppressDate" value="true"/>
</commentGenerator> <!-- !!!! Database Configurations !!!! -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://10.1.51.235:3306/jawavesys" userId="root" password="jawave88"/> <javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- !!!! Model Configurations !!!! -->
<javaModelGenerator targetPackage="com.goku.druid.demo.model" targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- !!!! Mapper XML Configurations !!!! -->
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator> <!-- !!!! Mapper Interface Configurations !!!! -->
<javaClientGenerator targetPackage="com.goku.druid.demo.mapper" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator> <!-- !!!! Table Configurations !!!! -->
<table tableName="user_" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false"/>
</context>
</generatorConfiguration>

Maven生成语句配置(mybatis-generator:generate

Mybatis基于XML配置SQL映射器(一)

Maven生成语句启动

修改 generatorConfig.xml 里 Table Configurations 的相关配置,然后启动生成

Mybatis基于XML配置SQL映射器(一)

Mybatis之SpringBoot配置

mybatis-spring-boot-starter方式

 <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>

application.properties配置

 # mybatis
mybatis.type-aliases-package=com.goku.mybatis.model
mybatis.mapper-locations=classpath:mapping/**/*.xml #pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

GITHUB

github :  https://github.com/nbfujx/learn-java-demo/tree/master/Goku.MybatisDemo.XML

上一篇:【POJ】2892 Tunnel Warfare


下一篇:squid源码安装下的conf文件默认值和提示