超详细超实用!!!零基础java开发之云风笔记接口开发之删除笔记(十一)

云风网
云风笔记
云风知识库

一、service/NoteApi新增delNode接口定义

public interface NoteApi {
    ...
    int deleteNote(NoteManage noteManage);
}

二、service/impl/NoteServiceImpl接口实现逻辑

public class NoteServiceImpl implements NoteApi {
    @Autowired
    NoteMapper noteMapper;
    ...

    public int delNote(int id){
        int count = 0;
        try {
            count = noteMapper.delNote(id);
        }catch (Exception err){
            System.out.println(err);
        }
        return count;
    }

}

三、mapper/NoteMapper新增接口

...
import org.apache.ibatis.annotations.Param;

public interface NoteMapper {
    ...
    int delNote(int noteId);
}
四、新增sql语句
<delete id="delNote">
    DELETE FROM note WHERE id = #{id}
</delete>
五、NoteManage添加获取id/设置id

之前更新接口已经声明,这里不用变更代码

六、控制类NoteController新增更新逻辑
 @RequestMapping(value = "/delNote",method = RequestMethod.POST)
public Response delNote(@RequestBody NoteManage noteManage){
    int id = noteManage.getNoteId();
    if(id!=0){
        int count = service.delNote(id);
        if(count>0){
            Response response = new Response(true,"删除成功",200);
            return response;
        }else {
            Response response = new Response(false,"删除失败",400);
            return response;
        }
    }else {
        Response response = new Response(false,"删除失败,请传入id",400);
        return response;
    }
}
六、接口请求测试

数据库原数据

在这里插入图片描述

删除笔记

在这里插入图片描述

在这里插入图片描述

删除成功!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

niech_cn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值