• 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.测试选择性修改

    将数据还原为原始数据

  • 相关阅读:
    热门Java开发工具IDEA入门指南——如何安装IntelliJ IDEA(上)
    在使用npm安装插件时,npm报错ERESOLVE
    ECharts 图形化看板 模板(简单实用)
    服务器大请求体问题定位
    [附源码]java毕业设计医院疫情疾控管理系统
    【初阶】C语言指针详解——指针必备的7大知识点
    销帮帮CRM与电商运营增效的关系?
    基于HTML5+CSS3小说阅读网站设计
    flink sql热加载自定义函数 不重启flink集群
    【Shell】sh执行脚本报错Syntax error: “(“ unexpected
  • 原文地址:https://blog.csdn.net/weixin_52385232/article/details/127672021