mybatis(1)
来源:互联网 发布:创维网络电视怎么样 编辑:程序博客网 时间:2024/06/14 11:01
环境准备
- JDK1.7
- 开发工具:Eclipse
- MYbatis:3.2.7
Mysql数据库
MyBatis下载
mybaits的代码由github.com管理,下载地址:https://github.com/mybatis/mybatis-3/releases
- 逆向生成自动生成配置信息:
-需要的jarb:mybatis-generator-core-1.3.2.jar
配置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="testTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/taotao" userId="root" password="cgx123"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- targetProject:生成PO类的位置 --> <javaModelGenerator targetPackage="com.taotao.pojo" targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 --> <sqlMapGenerator targetPackage="com.taotao.mapper" targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.taotao.mapper" targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 指定数据库表 --> <table schema="" tableName="tb_content"></table> <table schema="" tableName="tb_content_category"></table> <table schema="" tableName="tb_item"></table> <table schema="" tableName="tb_item_cat"></table> <table schema="" tableName="tb_item_desc"></table> <table schema="" tableName="tb_item_param"></table> <table schema="" tableName="tb_item_param_item"></table> <table schema="" tableName="tb_order"></table> <table schema="" tableName="tb_order_item"></table> <table schema="" tableName="tb_order_shipping"></table> <table schema="" tableName="tb_user"></table> </context></generatorConfiguration>
在main方法中执行,逆向生成配置信息
public class GeneratorSqlmap { public void generator() throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true; //指定 逆向工程配置文件 File configFile = new File("generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); } public static void main(String[] args) throws Exception { try { GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap(); generatorSqlmap.generator(); } catch (Exception e) { e.printStackTrace(); } }}
阅读全文
0 0
- MyBatis(1):MyBatis入门
- MyBatis(1):MyBatis入门
- MyBatis(1):MyBatis入门
- MyBatis(1):MyBatis入门
- MyBatis(1):MyBatis入门
- Mybatis(1)--什么是Mybatis
- mybatis(1)mybatis入门程序
- [MyBatis日记](1)MyBatis概述
- 【Mybatis】深入浅出MyBatis(1)-快速入门
- MyBatis学习(1)--MyBatis入门
- mybatis学习(1)---导入mybatis源码
- MyBatis学习(1)
- mybatis(1)
- Mybatis入门(1)
- Mybatis连载(1)
- Mybatis基础(1)
- Mybatis基础知识(1)
- Mybatis总结(1)
- spark中 transformation和action介绍
- 数据挖掘之数据准备
- 搭建Linux内核开发环境
- 一款优雅的干货集中营android客户端、实现沉浸式状态栏
- springMVC跨域请求配置前置增强器
- mybatis(1)
- NKOJ 3544 回文数(数学)
- 开机设置卡1为发送短信的默认sim卡
- 欧拉回路
- ARM嵌入式系统教程的外部存储器接口实验1
- 代码整洁_单元测试
- Win7(x64) + Cygwin + ns2.35 安装配置教程
- centos 7安装SPAMS
- Linux下的压缩文件剖析 (tar/gzip的区别)