超详细超实用!!!零基础java开发之云风笔记接口开发之删除笔记(十一)
云风网
云风笔记
云风知识库
一、service/NoteApi新增delNode接口定义
public interface NoteApi {...int deleteNote(NoteManage noteManage);
}
二、service/impl/NoteServiceImpl接口实现逻辑
public class NoteServiceImpl implements NoteApi {@AutowiredNoteMapper 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;}
}
六、接口请求测试
数据库原数据
删除笔记
删除成功!!!