查询专题接口添加
This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
@@ -31,4 +32,14 @@ public class CmsSubjectController {
|
||||
List<CmsSubject> subjectList = subjectService.listAll();
|
||||
return new CommonResult().success(subjectList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据专题名称分页获取专题")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getList(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
|
||||
List<CmsSubject> subjectList = subjectService.list(keyword, pageNum, pageSize);
|
||||
return new CommonResult().pageSuccess(subjectList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,13 @@ import java.util.List;
|
||||
* Created by macro on 2018/6/1.
|
||||
*/
|
||||
public interface CmsSubjectService {
|
||||
/**
|
||||
* 查询所有专题
|
||||
*/
|
||||
List<CmsSubject> listAll();
|
||||
|
||||
/**
|
||||
* 分页查询专题
|
||||
*/
|
||||
List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.mapper.CmsSubjectMapper;
|
||||
import com.macro.mall.model.CmsSubject;
|
||||
import com.macro.mall.model.CmsSubjectExample;
|
||||
import com.macro.mall.service.CmsSubjectService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,4 +24,15 @@ public class CmsSubjectServiceImpl implements CmsSubjectService {
|
||||
public List<CmsSubject> listAll() {
|
||||
return subjectMapper.selectByExample(new CmsSubjectExample());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
CmsSubjectExample example = new CmsSubjectExample();
|
||||
CmsSubjectExample.Criteria criteria = example.createCriteria();
|
||||
if (!StringUtils.isEmpty(keyword)) {
|
||||
criteria.andTitleLike("%" + keyword + "%");
|
||||
}
|
||||
return subjectMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user