超详细超实用!!!零基础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、测试接口请求