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

Mybatis-08.基础操作-删除

一.删除

接口方法 

package com.gjw.mapper;

import com.gjw.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface EmpMapper {
    // 根据ID删除数据
    @Delete("delete from emp where id = #{id}")
//    public void delete(Integer id);

    // delete方法其实是有返回值的,其返回值代表此次操作影响的记录数
    public int delete(Integer id);

}

如果将id写死,那么每次要删除新的员工信息时,就要重新修改代码,太过繁琐,因此我们使用动态获取的办法,使用mybatis当中提供的一个参数占位符“#{}”。在{}当中写上参数的名字。

测试代码

package com.gjw;

import com.gjw.mapper.EmpMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringbootMybatisCrudApplicationTests {

    @Autowired
    private EmpMapper empMapper;

    @Test
    void contextLoads() {
    }

    @Test
    public void testDelete() {
//        empMapper.delete(17);
        int delete = empMapper.delete(16);
        System.out.println(delete); // id = 17的记录以及删除过了,因此此次delete删除操作影响的记录数为0
    }

}

delete方法其实是有返回值的,它的返回值代表此次操作影响了几条记录数。 


http://www.kler.cn/news/366821.html

相关文章:

  • 2024 Rust现代实用教程:1.3获取rust的库国内源以及windows下的操作
  • 【Linux学习】(5)软件包管理器yum|编辑器vim
  • 视频美颜平台的搭建指南:基于直播美颜SDK的完整解决方案
  • SEO基础:什么是SERP?【百度SEO专家】
  • 大一物联网要不要转专业,转不了该怎么办?
  • Scala 提取器(Extractor)
  • 宠物电商新篇章:SpringBoot驱动的在线交易网站
  • 厨艺交流新天地:基于Spring Boot的解决方案
  • Qt Essential Classes
  • Java基础题:搬砖
  • Spring Boot环境下的厨艺社区构建
  • shell 基础
  • C#实现将汉字转换成拼音
  • [Gdiplus/Gdi]_[中级]_[实现多行文本的多种颜色绘制-富文本绘制]
  • 如何通过sip信令以及抓包文件分析媒体发到哪个地方
  • DEVOPS: 容器与虚拟化与云原生
  • java第三天(游戏开发)
  • grafana 和 prometheus
  • [论文阅读] Improved Baselines with Visual Instruction Tuning
  • ubuntu(27):ubuntu20.04鼠标无法显示但远程控制可以使用
  • 51c大模型~合集4
  • 重学SpringBoot3-集成Hazelcast
  • 基于GPT的智能客服落地实践
  • 深入解析Apache DolphinScheduler容错机制
  • 如何用 obdiag 排查 OceanBase数据库的卡合并问题——《OceanBase诊断系列》14
  • Sourcetree和GitLab的结合使用