﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-少年阿宾-随笔分类-Mybatis</title><link>http://www.blogjava.net/stevenjohn/category/52027.html</link><description>那些青春的岁月</description><language>zh-cn</language><lastBuildDate>Tue, 25 Dec 2012 20:00:45 GMT</lastBuildDate><pubDate>Tue, 25 Dec 2012 20:00:45 GMT</pubDate><ttl>60</ttl><item><title>MyBatis的动态SQL详解 </title><link>http://www.blogjava.net/stevenjohn/archive/2012/12/25/393451.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Tue, 25 Dec 2012 05:10:00 GMT</pubDate><guid>http://www.blogjava.net/stevenjohn/archive/2012/12/25/393451.html</guid><wfw:comment>http://www.blogjava.net/stevenjohn/comments/393451.html</wfw:comment><comments>http://www.blogjava.net/stevenjohn/archive/2012/12/25/393451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/stevenjohn/comments/commentRss/393451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/stevenjohn/services/trackbacks/393451.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MyBatis的动态SQL是基于OGNL表达式的，它可以帮助我们方便的在SQL语句中实现某些逻辑。MyBatis中用于实现动态SQL的元素主要有：&nbsp;ifchoose（when，otherwise）trimwheresetforeach if就是简单的条件判断，利用if语句我们可以实现某些简单的条件选择。先来看如下一个例子：Xml代码 &nbsp;&lt...&nbsp;&nbsp;<a href='http://www.blogjava.net/stevenjohn/archive/2012/12/25/393451.html'>阅读全文</a><img src ="http://www.blogjava.net/stevenjohn/aggbug/393451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/stevenjohn/" target="_blank">abin</a> 2012-12-25 13:10 <a href="http://www.blogjava.net/stevenjohn/archive/2012/12/25/393451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mybatis 自动生成代码工具</title><link>http://www.blogjava.net/stevenjohn/archive/2012/06/21/381280.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Thu, 21 Jun 2012 10:10:00 GMT</pubDate><guid>http://www.blogjava.net/stevenjohn/archive/2012/06/21/381280.html</guid><wfw:comment>http://www.blogjava.net/stevenjohn/comments/381280.html</wfw:comment><comments>http://www.blogjava.net/stevenjohn/archive/2012/06/21/381280.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/stevenjohn/comments/commentRss/381280.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/stevenjohn/services/trackbacks/381280.html</trackback:ping><description><![CDATA[<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">MyBatis中，可以使用Generator自动生成代码，包括DAO层、 MODEL层 、MAPPING SQL映射文件。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">第一步：下载MyBatis的Generator工具&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">下载地址：</span><a href="http://code.google.com/p/mybatis/downloads/detail?name=mybatis-generator-core-1.3.1-bundle.zip&amp;can=3&amp;q=Product%3DGenerator" target="_blank" style="color: #108ac6; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">http://code.google.com/p/mybatis/downloads/detail?name=mybatis-generator-core-1.3.1-bundle.zip&amp;can=3&amp;q=Product%3DGenerator</a>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">第二步：配置自动生成代码所需的XML配置文件，例如（generator.xml）&nbsp;</span>&nbsp;<br /><div>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</div><div>&lt;!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"&gt;</div><div>&lt;generatorConfiguration&gt;</div><div><span style="white-space:pre">	</span>&lt;!-- classPathEntry:数据库的JDBC驱动,换成你自己的驱动位置 --&gt;</div><div><span style="white-space:pre">	</span>&lt;classPathEntry location="D:\libs\ojdbc14.jar" /&gt;</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>&lt;context id="DB2Tables" targetRuntime="MyBatis3"&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- 去除自动生成的注释 --&gt;</div><div><span style="white-space:pre">		</span>&lt;commentGenerator&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="suppressAllComments" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/commentGenerator&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@172.16.88.10:1521:mydb" userId="abc" password="abc"&gt;</div><div><span style="white-space:pre">		</span>&lt;/jdbcConnection&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;javaTypeResolver &gt;</div><div><span style="white-space:pre">			</span>&lt;property name="forceBigDecimals" value="false" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaTypeResolver&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- targetProject:自动生成代码的位置 --&gt;</div><div><span style="white-space:pre">		</span>&lt;javaModelGenerator targetPackage="com.test.model" targetProject="E:\eclipse 3.5.2\workspace\gao\src"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="trimStrings" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaModelGenerator&gt;</div><div><span style="white-space:pre">		</span>&lt;sqlMapGenerator targetPackage="com.test.mapping" &nbsp;targetProject="E:\eclipse 3.5.2\workspace\gao\src"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/sqlMapGenerator&gt;</div><div><span style="white-space:pre">		</span>&lt;javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao" &nbsp;targetProject="E:\eclipse 3.5.2\workspace\gao\src"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaClientGenerator&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- tableName:用于自动生成代码的数据库表；domainObjectName:对应于数据库表的javaBean类名 --&gt;</div><div><span style="white-space:pre">		</span>&lt;table tableName="pds_system_item" domainObjectName="PdsSystemItem" /&gt;</div><div><span style="white-space:pre">		</span>&lt;table tableName="pds_system_level" domainObjectName="PdsSystemLevel" /&gt;</div><div><span style="white-space:pre">	</span>&lt;/context&gt;</div><div><span style="white-space:pre">		</span></div><div>&lt;/generatorConfiguration&gt;</div><div></div><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">将这个文件保存至你下载的mybatis-generator-core-1.3.1文件夹下&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">第三步：用命令行运行（记得选择自己的文件地址）&nbsp;</span>&nbsp;<br /><div>java -jar E:\soft\mybatis-generator-core-1.3.1\lib\mybatis-generator-core-1.3.1.jar -configfile E:\soft\mybatis-generator-core-1.3.1\genrator.xml -overwrite<br /><br /><br /><br /></div><div></div><br /><br />我自己写的如下：<br /><div>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</div><div>&lt;!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"&gt;</div><div>&lt;generatorConfiguration&gt;</div><div><span style="white-space:pre">	</span>&lt;!-- classPathEntry:数据库的JDBC驱动,换成你自己的驱动位置 --&gt;</div><div><span style="white-space:pre">	</span>&lt;classPathEntry location="D:\abin\Java\MybatisTool\mybatis-generator-core-1.3.1\lib\mysql-connector-java-5.1.20-bin.jar" /&gt;</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>&lt;context id="DB2Tables" targetRuntime="MyBatis3"&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- 去除自动生成的注释 --&gt;</div><div><span style="white-space:pre">		</span>&lt;commentGenerator&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="suppressAllComments" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/commentGenerator&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mycrm" userId="root" password="root"&gt;</div><div><span style="white-space:pre">		</span>&lt;/jdbcConnection&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;javaTypeResolver &gt;</div><div><span style="white-space:pre">			</span>&lt;property name="forceBigDecimals" value="false" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaTypeResolver&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- targetProject:自动生成代码的位置 --&gt;</div><div><span style="white-space:pre">		</span>&lt;javaModelGenerator targetPackage="com.test.model" targetProject="F:\nb\mp\src\main\java"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="trimStrings" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaModelGenerator&gt;</div><div><span style="white-space:pre">		</span>&lt;sqlMapGenerator targetPackage="com.test.mapping" &nbsp;targetProject="F:\nb\mp\src\main\java"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/sqlMapGenerator&gt;</div><div><span style="white-space:pre">		</span>&lt;javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao" &nbsp;targetProject="F:\nb\mp\src\main\java"&gt;</div><div><span style="white-space:pre">			</span>&lt;property name="enableSubPackages" value="true" /&gt;</div><div><span style="white-space:pre">		</span>&lt;/javaClientGenerator&gt;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">		</span>&lt;!-- tableName:用于自动生成代码的数据库表；domainObjectName:对应于数据库表的javaBean类名 --&gt;</div><div><span style="white-space:pre">		</span>&lt;table tableName="testcrm" domainObjectName="testcrmone" /&gt;</div><div><span style="white-space:pre">		</span>&lt;table tableName="testmy" domainObjectName="testmyone" /&gt;</div><div><span style="white-space:pre">	</span>&lt;/context&gt;</div><div><span style="white-space:pre">		</span></div><div>&lt;/generatorConfiguration&gt;</div><div></div><br /><img src ="http://www.blogjava.net/stevenjohn/aggbug/381280.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/stevenjohn/" target="_blank">abin</a> 2012-06-21 18:10 <a href="http://www.blogjava.net/stevenjohn/archive/2012/06/21/381280.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>