当前位置: 首页 > news >正文

怎么做网站劳务中介百度百度网址大全

怎么做网站劳务中介,百度百度网址大全,网站开发程序员的工资是多少,佛山微网站推广哪家专业文章目录 一、实战目标二、步骤概览1. 创建部门映射器接口2. 创建映射器配置文件3. 配置全局映射器4. 测试映射器接口 三、详细步骤1、创建部门映射器接口2、创建映射器配置文件3、配置全局映射器4、测试映射器接口 四、结语 一、实战目标 在本实战课程中,我们将学…

文章目录

  • 一、实战目标
  • 二、步骤概览
    • 1. 创建部门映射器接口
    • 2. 创建映射器配置文件
    • 3. 配置全局映射器
    • 4. 测试映射器接口
  • 三、详细步骤
    • 1、创建部门映射器接口
    • 2、创建映射器配置文件
    • 3、配置全局映射器
    • 4、测试映射器接口
  • 四、结语

在这里插入图片描述

一、实战目标

在本实战课程中,我们将学习如何在Spring Boot项目中使用配置方式整合MyBatis框架,并实现部门管理功能。

二、步骤概览

  1. 创建部门映射器接口
  2. 创建映射器配置文件
  3. 配置全局映射器
  4. 测试映射器接口

1. 创建部门映射器接口

net.huawei.hrsys_ssm.mapper包下创建DepartmentMapper接口,使用@Mapper注解标记。

2. 创建映射器配置文件

resources/mapper目录下创建DepartmentMapper.xml,定义SQL映射。

3. 配置全局映射器

在MyBatis配置文件中指定映射器配置文件位置和别名路径。

4. 测试映射器接口

创建TestDepartmentMapper类,使用@SpringBootTest注解进行测试。

三、详细步骤

1、创建部门映射器接口

@Mapper
public interface DepartmentMapper {int insert(Department department);int deleteById(int id);int update(Department department);Department findById(int id);List<Department> findAll();
}

2、创建映射器配置文件

  • DepartmentMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="net.huawei.hrsys_ssm.mapper.DepartmentMapper"><!-- 插入部门记录 --><insert id="insert" parameterType="Department"useGeneratedKeys="true" keyProperty="id">insert into department (name, number) values (#{name}, #{number});</insert><!-- 删除部门记录 --><delete id="deleteById" parameterType="int">delete from department where id = #{id};</delete><!-- 更新部门记录 --><update id="update" parameterType="Department">update department set name = #{name}, number = #{number} where id = #{id};</update><!-- 查询全部部门 --><select id="findAll" resultType="Department">select * from department;</select><!-- 创建结果映射,一个部门对应多个员工构成的集合 --><resultMap id="DepartmentWithEmployees" type="Department"><id property="id" column="id"/><result property="name" column="name"/><result property="number" column="number"/><collection property="employees" javaType="list" ofType="Employee"><id property="id" column="e_id"/><result property="age" column="age"/><result property="gender" column="gender"/><result property="name" column="e_name"/><result property="number" column="e_number"/><result property="depId" column="dep_id"/></collection></resultMap><!-- 按标识符查询部门记录 --><select id="findById" resultMap="DepartmentWithEmployees">select d.*, e.id e_id, e.age, e.gender, e.name e_name, e.number e_number, e.dep_idfrom department d left outer join employee e on d.id = e.dep_idwhere d.id = #{id};</select>
</mapper>

3、配置全局映射器

mapper-locations: classpath:mapper/*.xml
type-aliases-package: net.huawei.hrsys_ssm.bean

在这里插入图片描述

4、测试映射器接口

package net.huawei.hrsys_ssm;import net.huawei.hrsys_ssm.bean.Department;
import net.huawei.hrsys_ssm.mapper.DepartmentMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;/*** 功能:测试部门映射器接口* 作者:华卫* 日期:2024年09月25日*/
@SpringBootTest
public class TestDepartmentMapper {@Autowired // 自动装配部门映射器private DepartmentMapper departmentMapper;@Test // 测试查询全部部门public void testFindAll() {// 调用部门映射器的查询全部部门方法List<Department> departments = departmentMapper.findAll();// 利用Lambda表达式遍历部门列表departments.forEach(department -> System.out.println(department));}@Test // 测试按标识符查询部门public void testFindById() {// 定义标识符int id = 1;// 调用部门映射器的按标识符查询部门方法Department department = departmentMapper.findById(id);// 判断部门是否查询成功if (department != null) {System.out.println(department);} else {System.out.println("标识符为[" + id + "]的部门不存在~");}}@Test // 测试插入部门public void testInsert() {// 创建部门对象Department department = new Department();// 设置部门对象属性department.setName("后勤部");department.setNumber(5);// 调用部门映射器的插入方法int count = departmentMapper.insert(department);// 判断部门是否插入成功if (count > 0) {System.out.println("恭喜,部门记录插入成功~");System.out.println("插入的记录:" + departmentMapper.findById(5));} else {System.out.println("遗憾,部门记录插入失败~");}}@Test // 测试更新部门public void testUpdate() {// 查询id为5的部门Department department = departmentMapper.findById(5);// 输出更新前记录System.out.println("记录更新前:" + department);// 设置部门对象属性department.setName("保卫部");department.setNumber(555);// 调用部门映射器的更新部门方法int count = departmentMapper.update(department);// 判断部门是否更新成功if (count > 0) {System.out.println("恭喜,部门记录更新成功~");// 输出更新后记录System.out.println("记录更新后:" + departmentMapper.findById(5));} else {System.out.println("遗憾,部门记录更新失败~");}}@Test // 测试按标识符删除员工public void testDeleteById() {// 输出待删除记录System.out.println("待删除记录:" + departmentMapper.findById(5));// 调用部门映射器的按标识符删除部门方法int count = departmentMapper.deleteById(5);// 判断部门是否删除成功if (count > 0) {System.out.println("恭喜,部门记录删除成功~");} else {System.out.println("遗憾,部门记录删除失败~");}}
}

四、结语

通过本课程,你将掌握Spring Boot与MyBatis的整合,并能够实现部门管理的CRUD操作。

http://www.yayakq.cn/news/589543/

相关文章:

  • 广州网站设计公司滨州网站建设
  • 做网站主要是做什么算命手机网站开发
  • 网站关键词排名怎么提升图片怎么一键转换wordpress
  • 一般课程网站要怎么做潍坊专业网站建设价格
  • 官方在家做兼职的网站济南槐荫区做网站的
  • 网站开发成本评估做外贸需要浏览外国网站
  • 建一个网站大概需要多少钱建设银行网站会员注销
  • 成都科技网站建设热wordpress编辑器还原
  • 吴桥县网站建设价格金华建设网站公司
  • 专业网站建设组织手机家装绘图软件
  • 睢宁建网站全国做旅游开发的公司
  • 网站建设推广怎么玩电子制作diy
  • 漳州正规网站建设公司南康市建设局网站
  • 黑龙江省建设厅的网站更换wordpress图标
  • 专业单位网站开发优化公司
  • 网站如何做淘宝推广朋友做的网站图片不显示不出来的
  • 做彩票网站需要什么网站注册公司
  • 太白县住房和城乡建设局网站wap手机银行
  • 温江建设网站门户网站广告是什么
  • 从色彩度讨论如何建设一个网站.嘉兴网红打卡景点
  • 网站设计平台及开发工具湖北网站推广公司渠道
  • 平乡县网站建设平台网站客户运营
  • 网站底部的图标静态商城网页模板
  • 网站建设预算申请如何写网站建设绿茶
  • 30天网站建设全程实录Wordpress页面方块
  • 广东睿营建设有限公司网站网站建设大概需要多少费用
  • 网站信息建设企业网站建设流程与方法 论文
  • 中卫市建设局网站 冯进强东莞网页制作模版
  • 企业网站手机端模板下载静态网站素材
  • 南京市公共建设中心网站docker wordpress git