目录

  • 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数据库基本操作示例

4.8、Mybatis数据库基本操作示例

请大家根据需要的功能分别在StudentMapper.xml映射文件和测试程序文件中添加相应代码

1、模糊查询信息:

在映射文件中添加的代码(为了防止SQL注入,我们使用concat('%',#{value},'%')函数对模糊查询字符串进行了拼接

<!-- 配置查询功能,相当于一个名称为findStudentByName(String stuname)的方法 -->

<select id="findStudentByName" parameterType="String"resultType="entity.Student">

    select * from student where stuname like concat('%',#{value},'%')

</select>

在测试类文件中添加的代码(对个别系统中出现的中文乱码问题,我们在这里进行了简单处理):

List<Student> stu=ssion.selectList("entity.findStudentByName","z");

System.out.println(new String(stu.get(0).getStuname().getBytes("iso-8859-1"),"gbk"));

    从查询结果来看,使用模糊查询可以从数据库中查询出来一个对象集合。

2、更新信息

在映射文件中添加的代码:

<!-- 配置更新功能,相当于一个名称为updateStudent(entity.Student student)的方法 -->

    <select id="updateStudent" parameterType="entity.Student">

    update student set stuname=#{stuname},stuage=#{stuage},phone=#{phone}  where stuid = #{stuid}

    </select>

在测试类文件中添加的代码:

public class Test {

public static void main(String[] args)throws Exception {

//修改学生信息

Student s=new Student();

s.setStuname("job");

s.setStuage(23);

s.setPhone("15988888888");

s.setStuid(7);

new Test().updateStudent(s);

}

public void updateStudent(Student s)throws Exception{ 

InputStream inp=Resources.getResourceAsStream("mybatis-config.xml"); 

SqlSessionFactory sqlsession=new SqlSessionFactoryBuilder().build(inp);

SqlSession ssion=sqlsession.openSession();

//利用会话对象的更新功能从数据库中更新数据

ssion.update("entity.updateStudent",s);

//提交更新

ssion.commit();

ssion.close();

}

}

    从结果来看。我们正确的更新了id7的学生的信息

3、添加信息

在映射文件中添加的代码:

<!-- 配置插入功能,名称为addStudent(entity.Student student)的方法 -->

    <select id="addStudent" parameterType="entity.Student">

    insert into  student(stuid,stuname,stuage,phone) values(null,#{stuname},#{stuage},#{phone})

    </select>

在测试类文件中添加的代码:

public class Test {

public static void main(String[] args)throws Exception {

//添加学生信息

Student s=new Student();

s.setStuname("tom");

s.setStuage(30);

s.setPhone("15959595959");

new Test().addStudent(s);

}

 

public void addStudent(Student s)throws Exception{

InputStream inp=Resources.getResourceAsStream("mybatis-config.xml"); 

SqlSessionFactory sqlsession=new SqlSessionFactoryBuilder().build(inp); 

SqlSession ssion=sqlsession.openSession();

//利用会话对象的添加功能往数据库中添加数据

ssion.insert("addStudent", s);

//提交更新

ssion.commit();

ssion.close();

}

}

    从结果来看。我们正确的添加了新的学生的信息

4、删除信息

在映射文件中添加的代码:

<!-- 配置删除功能,名称为delStudentById(entity.Student student)的方法 -->

    <select id="delStudent" parameterType="entity.Student">

    delete from student where stuid=#{stuid}

    </select>

在测试类文件中添加的代码:

public class Test {

public static void main(String[] args)throws Exception {

//删除学生信息

Student s=new Student();

s.setStuid(6);

new Test().delStudent(s);

}

 

public void delStudent(Student s)throws Exception{ 

InputStream inp=Resources.getResourceAsStream("mybatis-config.xml"); 

SqlSessionFactory sqlsession=new SqlSessionFactoryBuilder().build(inp); 

SqlSession ssion=sqlsession.openSession();

//利用会话对象的删除功能从数据库中删除数据

ssion.delete("entity.delStudent",s);

 

//提交更新

ssion.commit();

ssion.close();

} }