`
thrillerzw
  • 浏览: 139132 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

mybatis

 
阅读更多

。。。

 

 

//常用类型
jdbcType=VARCHAR
jdbcType=INTEGER
jdbcType=CHAR
jdbcType=BIGINT
jdbcType=TIMESTAMP

//注意and
<if test="state != null and state !=''" >
     s.state=#{state,jdbcType=VARCHAR}  and
</if>

//小于号需要CDATA ,因为xml不允许出现类似“<”这样的字符,可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析。
<![CDATA[
	 ROWNUM <= #{end,jdbcType=BIGINT} ) ts 
]]>

//不可以使用#
from xxtable_${suffix}

 

<insert id="insert" parameterType="com.dhgate.cms.po.model.ModelDataPo">
  <selectKey resultType="int" keyProperty="id" >
   select LAST_INSERT_ID() as id     
  </selectKey>
  insert into ${tableName} (${fields}) values (${vals})
 </insert>
 
foreach 循环
<foreach collection="auditstatusArr" item="auditStatus" separator="or" open="(" close=")">
         audit_status = #{auditStatus}
</foreach> 
 
oracle insert 主键:
<selectKey resultType="long" keyProperty="id">  
         SELECT SEQ_TEST.NEXTVAL FROM DUAL  
</selectKey> 
 
执行sql,如创建表  ,接口public void executeSql(String value);或者用update 、insert都可以

 <select id="executeSql" parameterType="java.lang.String">${value}</select> 

 

#{} 解析的是占位符?可以防止SQL注入, 比如打印出来的语句 select * from table where id=?然而${} 则是不能防止SQL注入,用${}保证原样输出 

 
mybatis用mysql 函数
update td_model set last_update_date=CURRENT_TIMESTAMP()  //2014-10-15 15:23:32

下载mybatis-generator-core-1.3.2.jar:
https://github.com/mybatis/generator/releases

 

文件名: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="DB2Tables" targetRuntime="MyBatis3"> 
<!-- 去除自动生成的注释 --> 
<commentGenerator> 
<property name="suppressAllComments" value="true" /> 
</commentGenerator> 

<!-- 数据库连接信息 --> 
<jdbcConnection driverClass="com.mysql.jdbc.Driver" 
connectionURL="jdbc:mysql://ip:port/testdb" userId="xx" 
password="xx"> 
</jdbcConnection> 

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

<!-- po实体代码位置 --> 
<javaModelGenerator targetPackage="com.xx.xx.po.confinterface" 
targetProject="D:\\xx\\workspace\\xx-web\\src\\main\\java"> 
<property name="enableSubPackages" value="true" /> 
<property name="trimStrings" value="true" /> 
</javaModelGenerator> 

<!-- sql代码的xml映射文件位置 --> 
<sqlMapGenerator targetPackage="com.xx.xx.mapper.confinterface" 
targetProject="D:\\xx\\workspace\\xx-web\\src\\main\\resources"> 
<property name="enableSubPackages" value="true" /> 
</sqlMapGenerator> 

<!-- mapper接口位置 --> 
<javaClientGenerator type="XMLMAPPER" 
targetPackage="com.xx.xx.mapper.confinterface" 
targetProject="D:\\x\\workspace\\xx-web\\src\\main\\java"> 
<property name="enableSubPackages" value="true" /> 
</javaClientGenerator> 


<!-- 需要自动生成的表 --> 
<table tableName="td_conf_interface" domainObjectName="ConfInterface" enableCountByExample="false" 
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> 
<!--true:则po、xml中跟数据库字段一样。false: MyBatis Generator会将数据库中实际的字段名字转换为Camel Case风格作为生成的实体类的属性名。 --> 
<property name="useActualColumnNames" value="false" /> 
<generatedKey column="id" sqlStatement="mysql" identity="true" /> 
</table> 

</context> 
</generatorConfiguration>

main类
import com.xx.mybatis.generator.GeneratorUtil;

public class Generator {

    public static void main(String[] args) {
       // GeneratorUtil.generate("D:\\xx\\workspace\\xx-xx-web\\src\\test\\java\\generatorConfig.xml");
    }
}

 

分享到:
评论

相关推荐

    MyBatis-Plus入门+MyBatis-Plus文档手册 中文pdf高清版.rar

    mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中通过SQL语句操作数据库,很是灵活。但正其操作都要通过SQL语句进行,就必须写大量的xml文件,很是麻烦。mybatis-plus就很好的...

    mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip

    mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip ...

    mybatis-3-config/mapper.dtd 解决mybatis头文件报错

    解决mybatis头文件报错 下载好压缩包 解压将文件放到本地文件夹 例如 D盘的哪个文件夹 D:\mybatis\ ;然后打开eclipse -&gt;Window-&gt;prefenrence-&gt;XML-&gt;XML Catalog-&gt;User Specifiled Entreis-&gt;Add-&gt;Location(此处是你...

    MyBatis-Plus 的官方示例(mybatis-plus-samples-master.zip)

    本工程为 MyBatis-Plus 的官方示例,项目结构如下: mybatis-plus-sample-quickstart: 快速开始示例 mybatis-plus-sample-quickstart-springmvc: 快速开始示例(Spring MVC版本) mybatis-plus-sample-reduce-...

    free-idea-mybatis2019.12.18.zip

    free-idea-mybatis is an enchange plugin for idea to supoort mybatis,here is the main functions: generate mapper xml files navigate from the code to mapper and from the mapper back to code auto code...

    mybatis-spring-2.0.0-API文档-中文版.zip

    赠送jar包:mybatis-spring-2.0.0.jar; 赠送原API文档:mybatis-spring-2.0.0-javadoc.jar; 赠送源代码:mybatis-spring-2.0.0-sources.jar; 赠送Maven依赖信息文件:mybatis-spring-2.0.0.pom; 包含翻译后的API...

    mybatis-generator-core-1.3.7-API文档-中文版.zip

    赠送jar包:mybatis-generator-core-1.3.7.jar; 赠送原API文档:mybatis-generator-core-1.3.7-javadoc.jar; 赠送源代码:mybatis-generator-core-1.3.7-sources.jar; 赠送Maven依赖信息文件:mybatis-generator-...

    mybatis慢SQL插件

    基于mybatis的慢SQL小插件,原理是mybatis拦截器。只需要在springboot的配置文件做简单的配置,mybatis拦截器将SQL中所有参数自动做了填充。拦截器监控慢SQL并将完整的可执行的SQL语句打印在日志文件中,复制该SQL...

    mybatis-3.5.9-API文档-中文版.zip

    赠送jar包:mybatis-3.5.9.jar; 赠送原API文档:mybatis-3.5.9-javadoc.jar; 赠送源代码:mybatis-3.5.9-sources.jar; 赠送Maven依赖信息文件:mybatis-3.5.9.pom; 包含翻译后的API文档:mybatis-3.5.9-javadoc-...

    《深入浅出MyBatis技术原理与实战》高清完整PDF下载

    当前已经是移动互联网时代,Java持久框架Hibernate没有办法适应高性能,灵活,大数据,可优化等要求,这时MyBatis就进入了我们的视野,随着移动互联网应用的持续发酵,Spring MyBatis的应用已在Java互联网平台上得到...

    开发工具 mybatis-3.4.2

    开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2...

    mybatis3.5.7.zip

    MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 ...

    MybatisGenerate_代码生成_tkMybatis_mybatisgenerate_mybatis_

    生成已tk.mybatis封装的mybatis代码

    mybatis-3.2.5.jar及mybatis-spring-1.2.2.jar

    MyBatis-Spring 会帮助你将 MyBatis 代码无缝地整合到 Spring 中。 使用这个类库中的类, Spring 将会加载必要的 MyBatis 工厂类和 session 类。 这个类库也提供一个简单的方式来注入 MyBatis 数据映射器和 ...

    mybatis-3-mybatis-3.2.6

    mybatis源码是mybatis-3.2.6的源码,用户使用mybatis时可以进行参考

    深入浅出MyBatis技术原理与实战(高清带目录版)

    随着大数据时代的到来,Java 持久层框架MyBatis 已经成为越来越多企业的选择。遗憾的是,时至今日国内依然没有一本讨论MyBatis 的书,这增加了初学者的学习难度,初学者往往只能基于零星的案例来学习MyBatis,无法...

    springmvc+Mybatis+activiti5

    此项目为springmvc、Mybatis、EHcache、maven、Spring security3、activiti5工作流的整合 是一个基于数据库的权限管理demo项目、使用mysql数据库 项目运行前需要构建maven私服 而且有些jar包私服中肯定没有,需要...

    mybatis-spring.jar 最新版 适配MyBatis-3.4.0及以上

    该jar包是Mybatis和Spring整合必备jar包,适配Mybatis-3.4.0及以上版本。

    mybatis-3-config.dtd mybatis-3-mapper.dtd

    mybatis配置的重要文件包括mybatis-3-config.dtd mybatis-3-mapper.dtd

    【BAT必备】mybatis面试题

    【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT必备】mybatis面试题【BAT...

Global site tag (gtag.js) - Google Analytics