zoukankan      html  css  js  c++  java
  • mybatis 高级映射和spring整合之逆向工程(7)

    mybatis 高级映射和spring整合之逆向工程(7)

    4.0 逆向工程
        4.1 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需的代码(mapper.java,mapper.xml,po..)
    
        企业实际开发中,常用的逆向工程方式:
        由数据库的表生成java代码。
    
        4.2 下载逆向工程
                mybatis-generator-core-1.3.2-bundle
        4.3 使用方法(会用)
            4.3.1 运行逆向工程(建议使用java程序方式,不依赖开发工具)
            4.3.2 生成代码配置文件
    
            <!-- targetProject:生成po类的位置 -->
            <javaModelGenerator targetPackage="com.demo.ssm.pc">
            ....
            <!-- targetProject:mapper映射文件生成的位置 -->
            <javaModelGenerator targetPackage="com.demo.ssm.mapper">
            ....
            <!-- targetProject:mapper接口生成的位置 -->
            <javaClientGenerator type="XMLMAPPER">
                targetPackage="com.demo.ssm.mapper"
                targetPackage=".src">
            ....
            <!-- 指定数据库表 -->
            <table tableName="items"></table>
            <table tableName="orders"></table>
            <table tableName="orderdetail"></table>
            <table tableName="user"></table>
            4.3.3 执行生成程序
            List<string> warnings = new ArrayList<String>();
            boolean overwrite = true;
            //指定逆向工程配置文件
            File configFile = new File("generatorConfig.xml");
    
            4.3.4 使用生成的文件
            需要将生成工程中所生成的代码拷贝到自己的工程中。
    
            测试itemsMapper中的方法
    
            //自定义条件查询
            @Test
            public void testSelectByExample(){
                ItemsExample itemsExample = new itemsExample.createCriteria();
                Criteria.andNameEqualTo("笔记本3");
                //可能返回多条记录
                List<items>list = itemsMapper.selectByExample(itemsExample);
                System.out.println(list);
            }
            //根据主键查询
            @Test
            public void testSelectByPrimaryKey(){
                Items items = itemsMapper.selectByPrimaryKey(1);
                System.out.println(items);
            }
            //更新数据
            @Test
            public void testUpdateByPrimaryKey(){
                //对所有字段进行更新,需要先查询出来再更新
                Items items = itemsMapper.selectByPrimaryKey(1);
                items.setName("水杯");
                itemsMapper.updateByPrimaryKey(items);
                    //如果出入字段不为空才更新,在批量更新中使用此方法,不需要先查询再更新
                    //itemsMapper.updateByPrimaryKeySelective(record);
            }
    
    
  • 相关阅读:
    整理:分页存储过程整理
    净利润-流通市值比率”与公司估值
    常见7种股票底部形态(图解)
    nginx
    移动成本分布1
    浅谈公开信息检索和判断能力
    股票技术分析 成交量与换手率专题
    成份股和成份股指数
    股票底部形态初探
    筹码拉抬派发法
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6468012.html
Copyright © 2011-2022 走看看