超详细超实用!!!零基础java开发之云风笔记笔记列表接口条件查询(九)

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

笔记列表数据接口条件查询,一般是分页获取/以及各个参数查询获取数据

1、改造service/NoteApi接口定义

原有定义:

public interface NoteApi {
    ...
    List<NoteManage> getNoteList();
}

现加入name/content参数

public interface NoteApi {
	...
    List<NoteManage> getNoteList(String searchName,String name,String content);
}
2、改造service/impl/NoteServiceImpl接口实现
public List<NoteManage> getNoteList(String searchName,String name,String content){
   return noteMapper.getNoteList(searchName,name,content);
}
3、改造mapper/NoteMapper
public interface NoteMapper {
    ...
    List<NoteManage> getNoteList(String searchName,String name,String content);
}
4、改造sql语句
<select id="getNoteList" resultType="com.example.study.note.NoteManage">
    SELECT * FROM `note`
    <where>
         <if test="searchName!= null and searchName!= ''">
             and name like concat('%',#{searchName},'%') or type like concat('%',#{searchName},'%') or content like concat('%',#{searchName},'%')
         </if>
         <if test="name!= null and name!= ''">
             and name like concat('%',#{name},'%')
         </if>
         <if test="content!= null and content!= ''">
             and content like concat('%',#{content},'%')
         </if>
     </where>
</select >
5、改造NoteManage

已存在setName/getName、setContent/getContent。所以不需要变更逻辑代码

6、改造控制类NoteController
@RequestMapping(value = "/getNoteList",method = RequestMethod.POST)
public Response getNoteList(@RequestBody NoteManage noteManage){
	String searchName = noteManage.getSearchName();
    String name = noteManage.getName();
    String content = noteManage.getContent();
    Response response = new Response();
    List<NoteManage> noteList = service.getNoteList(searchName,name,content);
    response.setResponse(true,"查询成功",200,noteList);
    return response;
}
7、测试接口请求

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

niech_cn

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

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

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

打赏作者

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

抵扣说明:

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

余额充值