• MyBatis的逆向工程之奢华尊享版


    MyBatis的逆向工程之奢华尊享版

    逆向工程的配置文件 generatorConfig.xml

    将targetRuntime修改为:targetRuntime="MyBatis3"

    1. "1.0" encoding="UTF-8"?>
    2. generatorConfiguration
    3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
    5. <generatorConfiguration>
    6. <context id="DB2Tables" targetRuntime="MyBatis3">
    7. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    8. connectionURL="jdbc:mysql://localhost:3306/ssm"
    9. userId="root"
    10. password="123456">
    11. jdbcConnection>
    12. <javaModelGenerator targetPackage="com.atguigu.mybatis.pojo"
    13. targetProject=".\src\main\java">
    14. <property name="enableSubPackages" value="true"/>
    15. <property name="trimStrings" value="true"/>
    16. javaModelGenerator>
    17. <sqlMapGenerator targetPackage="com.atguigu.mybatis.mapper"
    18. targetProject=".\src\main\resources">
    19. <property name="enableSubPackages" value="true"/>
    20. sqlMapGenerator>
    21. <javaClientGenerator type="XMLMAPPER"
    22. targetPackage="com.atguigu.mybatis.mapper" targetProject=".\src\main\java">
    23. <property name="enableSubPackages" value="true"/>
    24. javaClientGenerator>
    25. <table tableName="t_emp" domainObjectName="Emp"/>
    26. <table tableName="t_dept" domainObjectName="Dept"/>
    27. context>
    28. generatorConfiguration>

    测试

    1. public class MBGTest {
    2. @Test
    3. public void testMBG(){
    4. SqlSession sqlSession = SqlSessionUtil.getSqlSession();
    5. EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
    6. //1.根据id来查询数据
    7. /*Emp emp = mapper.selectByPrimaryKey(1);
    8. System.out.println(emp);*/
    9. //2.查询所有数据
    10. /*List list = mapper.selectByExample(null);
    11. list.forEach(System.out::println);*/
    12. //3.根据条件来查询数据
    13. /*EmpExample example = new EmpExample();
    14. example.createCriteria().andEmpNameEqualTo("张三").andAgeGreaterThanOrEqualTo(20);
    15. example.or().andGenderEqualTo("男");
    16. List list = mapper.selectByExample(example);
    17. list.forEach(System.out::println);*/
    18. //4.测试普通修改功能
    19. /*Emp emp = new Emp(1,"小黑",null,"女");
    20. mapper.updateByPrimaryKey(emp);*/
    21. //5.测试选择性修改
    22. Emp emp = new Emp(1,"小黑",null,"女");
    23. mapper.updateByPrimaryKeySelective(emp);
    24. }
    25. }

    原始数据

    1.根据id来查询数据

    2.查询所有数据

    3.根据条件来查询数据

    4.测试普通修改功能

    5.测试选择性修改

    将数据还原为原始数据

  • 相关阅读:
    动态规划经典入门
    kettle遇到的问题-脚本启动系统找不到指定路径
    美联储历次加息周期及结果
    2022年11月华南师范大学自考本科-《计算机信息管理课程实验—C++程序设计》实践题目
    Stm32_标准库_16_串口&蓝牙模块_手机与蓝牙模块通信_手机传入信息能对芯片时间日期进行更改
    django-vue系统报错解决记录
    Linux 信号捕捉函数 signal sigaction
    【docker配置mysql主从复制模式】
    Peter算法小课堂—蠕动区间
    LeetCode_496_下一个更大元素Ⅰ
  • 原文地址:https://blog.csdn.net/weixin_52385232/article/details/127672021