目录

  • 1 2023广东省精品课程评审申报章节
    • 1.1 申报书
    • 1.2 总结报告
    • 1.3 课程数据信息表
    • 1.4 自评报告
    • 1.5 专家组评语
    • 1.6 相关佐证
  • 2 2020校精品课程评审申报章节
    • 2.1 验收材料总文档
    • 2.2 精品开放课程申报书
    • 2.3 精品开放课程结题验收报告书
    • 2.4 精品开放课程结题验收总结报告
    • 2.5 精品开放课程结题验收项目汇总表
    • 2.6 佐证1.课程基础与建设目标
      • 2.6.1 校本教材
      • 2.6.2 论文
    • 2.7 佐证2.课程设计
      • 2.7.1 课程定位
      • 2.7.2 建设方式
    • 2.8 佐证3.更新与共享
      • 2.8.1 吸引力
      • 2.8.2 内容更新
      • 2.8.3 媒体应用
    • 2.9 佐证4.教学团队
      • 2.9.1 负责人
      • 2.9.2 教学队伍
    • 2.10 佐证5.教学资源
      • 2.10.1 基本资源
        • 2.10.1.1 单元设计
        • 2.10.1.2 课件PPT
        • 2.10.1.3 授课视频
      • 2.10.2 拓展资源
      • 2.10.3 资源创新
    • 2.11 佐证6.课程特色
      • 2.11.1 内容
      • 2.11.2 教学组织
      • 2.11.3 教学模式
    • 2.12 佐证7.目标实现
      • 2.12.1 考评
      • 2.12.2 能学
      • 2.12.3 辅教
  • 3 第一章 Spring 简介
    • 3.1 思政教育
    • 3.2 Sring 概述
    • 3.3 Spring 优点
    • 3.4 Spring 框架结构
    • 3.5 Spring 框架特征
    • 3.6 Spring 入门程序
    • 3.7 Spring 依赖注入
    • 3.8 本章小结
    • 3.9 习题1
  • 4 第二章 Spring中bean的配置和实例化
    • 4.1 思政教育
    • 4.2 Spring中bean的配置
    • 4.3 Bean的实例化
    • 4.4 bean的作用域
    • 4.5 Bean的生命周期
    • 4.6 Bean的装配方式
    • 4.7 应用案例:Annotation注解
    • 4.8 本章小结
    • 4.9 习题2
  • 5 第三章  Spring面向切面编程AOP
    • 5.1 Spring  AOP的基本概念
    • 5.2 通知类型介绍
    • 5.3 JDK动态代理
    • 5.4 Spring AOP
    • 5.5 应用案例:AspectJ开发
    • 5.6 本章小结
    • 5.7 习题3
  • 6 第四章  Mybatis原理
    • 6.1 基本内容
    • 6.2 JDBC的问题
    • 6.3 Hibernate的问题
    • 6.4 MyBatis优势
    • 6.5 MyBatis的工作原理
    • 6.6 MyBatis的数据库准备_MySQL
    • 6.7 应用案例:MyBatis入门程序
    • 6.8 Mybatis数据库基本操作示例
    • 6.9 习题4
  • 7 第五章  Mybatis反向工程
    • 7.1 动态SQL
    • 7.2 应用案例: Mybatis反向(逆向)工程
    • 7.3 Mybatis反向(逆向)工程代码解读
    • 7.4 习题5
  • 8 第六章  Spring、 Mybatis Mapper接口编程
    • 8.1 Mybatis反向工程生成的接口
    • 8.2 应用案例:SpringMVC、 Mybatis  Mapper接口编程
    • 8.3 习题6
  • 9 SpringMVC
    • 9.1 SpringMVC框架
    • 9.2 应用案例:SpringMVC
    • 9.3 应用案例:SpringMVC注解开发
    • 9.4 习题7
  • 10 SpringMVC数据绑定
    • 10.1 SpringMvc的数据绑定流程
    • 10.2 应用案例:SpringMVC参数绑定
    • 10.3 SpringMVC参数绑定数组和集合
    • 10.4 案例SpringMVC参数绑定数组
    • 10.5 习题8
  • 11 第九章、SpringMVC拦截器
    • 11.1 拦截器的实现
    • 11.2 拦截器的配置
    • 11.3 应用案例
    • 11.4 习题9
  • 12 第十章 文件上传
    • 12.1 文件上传原理
    • 12.2 创建工程
    • 12.3 应用案例
    • 12.4 习题10
  • 13 第十一章、课程资源管理系统
    • 13.1 系统需求
    • 13.2 开发环境
    • 13.3 数据库设计
    • 13.4 项目程序设计
  • 14 第十二章 职场沟通技能
    • 14.1 职场沟通原则与理念
  • 15 第十三章 如何与上司、同事沟通
    • 15.1 如何与上司、同事沟通
  • 16 第十四章 软件开发团队建设
    • 16.1 企业级应用开发团队组织技巧培训
Mybatis反向(逆向)工程代码解读

5.2 Mybatis反向(逆向)工程代码解读

反向工程生成了两个包entity和mapper,并且在这两个包中生成了8个文件。由于我们只针对两个表进行了反射工程同,所以每个数据库表对应4个文件。其中student表对应的4个文件分别为Student.java、StudentExample.java、StudentMapper.java和StudentMapper.xml。

1、 Student.java为实体类,该类中的属性与数据库中表的字段一一对应。

2、 StudentExample.java为查询条件生成类,该类负责生成执行增删改查时需要的各种条件。该类生成的查询条件是由动态SQL组成的,具有强大的组合能力和适应性。

3、 StudentMapper.java是一个接口,其中定义了重要的数据库操作方法,该接口和配置文件StudentMapper.xml一起通过Mybits框架实现各种数据库操作。其代码如下:

package mapper;

import entity.Student;

import entity.StudentExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface StudentMapper {

    int countByExample(StudentExample example);

    int deleteByExample(StudentExample example);

    int deleteByPrimaryKey(Integer stuid);

    int insert(Student record);

    int insertSelective(Student record);

    List<Student> selectByExample(StudentExample example);

    Student selectByPrimaryKey(Integer stuid);

    int updateByExampleSelective(@Param("record") Student record, @Param("example") StudentExample example);

    int updateByExample(@Param("record") Student record, @Param("example") StudentExample example);

    int updateByPrimaryKeySelective(Student record);

    int updateByPrimaryKey(Student record);

}

4、 StudentMapper.xml中配置了各种操作数据库的功能,其代码如下:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="mapper.StudentMapper" >

  <resultMap id="BaseResultMap" type="entity.Student" >

    <id column="stuid" property="stuid" jdbcType="INTEGER" />

    <result column="stuname" property="stuname" jdbcType="VARCHAR" />

    <result column="stuage" property="stuage" jdbcType="INTEGER" />

  </resultMap>

  <sql id="Example_Where_Clause" >

    <where >

      <foreach collection="oredCriteria" item="criteria" separator="or" >

        <if test="criteria.valid" >

          <trim prefix="(" suffix=")" prefixOverrides="and" >

            <foreach collection="criteria.criteria" item="criterion" >

              <choose >

                <when test="criterion.noValue" >

                  and ${criterion.condition}

                </when>

                <when test="criterion.singleValue" >

                  and ${criterion.condition} #{criterion.value}

                </when>

                <when test="criterion.betweenValue" >

                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

                </when>

                <when test="criterion.listValue" >

                  and ${criterion.condition}

                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >

                    #{listItem}

                  </foreach>

                </when>

              </choose>

            </foreach>

          </trim>

        </if>

      </foreach>

    </where>

  </sql>

  <sql id="Update_By_Example_Where_Clause" >

    <where >

      <foreach collection="example.oredCriteria" item="criteria" separator="or" >

        <if test="criteria.valid" >

          <trim prefix="(" suffix=")" prefixOverrides="and" >

            <foreach collection="criteria.criteria" item="criterion" >

              <choose >

                <when test="criterion.noValue" >

                  and ${criterion.condition}

                </when>

                <when test="criterion.singleValue" >

                  and ${criterion.condition} #{criterion.value}

                </when>

                <when test="criterion.betweenValue" >

                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

                </when>

                <when test="criterion.listValue" >

                  and ${criterion.condition}

                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >

                    #{listItem}

                  </foreach>

                </when>

              </choose>

            </foreach>

          </trim>

        </if>

      </foreach>

    </where>

  </sql>

  <sql id="Base_Column_List" >

    stuid, stuname, stuage

  </sql>

  <select id="selectByExample" resultMap="BaseResultMap" parameterType="entity.StudentExample" >

    select

    <if test="distinct" >

      distinct

    </if>

    <include refid="Base_Column_List" />

    from student

    <if test="_parameter != null" >

      <include refid="Example_Where_Clause" />

    </if>

    <if test="orderByClause != null" >

      order by ${orderByClause}

    </if>

  </select>

  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >

    select

    <include refid="Base_Column_List" />

    from student

    where stuid = #{stuid,jdbcType=INTEGER}

  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >

    delete from student

    where stuid = #{stuid,jdbcType=INTEGER}

  </delete>

  <delete id="deleteByExample" parameterType="entity.StudentExample" >

    delete from student

    <if test="_parameter != null" >

      <include refid="Example_Where_Clause" />

    </if>

  </delete>

  <insert id="insert" parameterType="entity.Student" >

    insert into student (stuid, stuname, stuage

      )

    values (#{stuid,jdbcType=INTEGER}, #{stuname,jdbcType=VARCHAR}, #{stuage,jdbcType=INTEGER}

      )

  </insert>

  <insert id="insertSelective" parameterType="entity.Student" >

    insert into student

    <trim prefix="(" suffix=")" suffixOverrides="," >

      <if test="stuid != null" >

        stuid,

      </if>

      <if test="stuname != null" >

        stuname,

      </if>

      <if test="stuage != null" >

        stuage,

      </if>

    </trim>

    <trim prefix="values (" suffix=")" suffixOverrides="," >

      <if test="stuid != null" >

        #{stuid,jdbcType=INTEGER},

      </if>

      <if test="stuname != null" >

        #{stuname,jdbcType=VARCHAR},

      </if>

      <if test="stuage != null" >

        #{stuage,jdbcType=INTEGER},

      </if>

    </trim>

  </insert>

  <select id="countByExample" parameterType="entity.StudentExample" resultType="java.lang.Integer" >

    select count(*) from student

    <if test="_parameter != null" >

      <include refid="Example_Where_Clause" />

    </if>

  </select>

  <update id="updateByExampleSelective" parameterType="map" >

    update student

    <set >

      <if test="record.stuid != null" >

        stuid = #{record.stuid,jdbcType=INTEGER},

      </if>

      <if test="record.stuname != null" >

        stuname = #{record.stuname,jdbcType=VARCHAR},

      </if>

      <if test="record.stuage != null" >

        stuage = #{record.stuage,jdbcType=INTEGER},

      </if>

    </set>

    <if test="_parameter != null" >

      <include refid="Update_By_Example_Where_Clause" />

    </if>

  </update>

  <update id="updateByExample" parameterType="map" >

    update student

    set stuid = #{record.stuid,jdbcType=INTEGER},

      stuname = #{record.stuname,jdbcType=VARCHAR},

      stuage = #{record.stuage,jdbcType=INTEGER}

    <if test="_parameter != null" >

      <include refid="Update_By_Example_Where_Clause" />

    </if>

  </update>

  <update id="updateByPrimaryKeySelective" parameterType="entity.Student" >

    update student

    <set >

      <if test="stuname != null" >

        stuname = #{stuname,jdbcType=VARCHAR},

      </if>

      <if test="stuage != null" >

        stuage = #{stuage,jdbcType=INTEGER},

      </if>

    </set>

    where stuid = #{stuid,jdbcType=INTEGER}

  </update>

  <update id="updateByPrimaryKey" parameterType="entity.Student" >

    update student

    set stuname = #{stuname,jdbcType=VARCHAR},

      stuage = #{stuage,jdbcType=INTEGER}

    where stuid = #{stuid,jdbcType=INTEGER}

  </update>

</mapper>

    StudentMapper.xml配置文件使用Spring和Mybatis框架共同配合封装了大量操作数据库的功能,这些功能可以通过调用StudentMapper.java接口中的方法来实现,具体使用请参看第六章。