首页>代码>Springboot + mybatis + layui实现的增删改查项目实例>/yy/src/main/java/cn/lj/yy/controller/PersonController.java
package cn.lj.yy.controller;

import cn.lj.yy.model.Person;
import cn.lj.yy.service.PersonService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "Person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @RequestMapping(value = "getAllPersonList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public String getAllPersonList(HttpServletRequest request) {
        int pageSize = Integer.parseInt(request.getParameter("limit"));
        int pageNumber = Integer.parseInt(request.getParameter("page"));
        PageHelper.startPage(pageNumber, pageSize);

        String _id = request.getParameter("id");
        int id = 0;
        if (_id != null && !"".equals(_id)) {
            id = Integer.parseInt(_id);
        }
        String name = request.getParameter("name");

        Map params = new HashMap();
        params.put("id", id);
        params.put("name", name);

        Page<Person> data = personService.getAllPersonByPage(params);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("count", data.getTotal());
        jsonObject.put("data", data);
        return jsonObject.toJSONString();
    }

    @RequestMapping(value = "addPerson", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String addPerson(Person person) {
        JSONObject jsonObject = new JSONObject();
        if (personService.addPerson(person)) {
            jsonObject.put("success", true);
            jsonObject.put("message", "添加人员信息成功");
        } else {
            jsonObject.put("success", false);
            jsonObject.put("message", "添加人员信息失败");
        }
        return jsonObject.toJSONString();
    }

    @RequestMapping(value = "updatePerson", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String updatePerson(Person person) {
        JSONObject jsonObject = new JSONObject();
        if (personService.updatePerson(person)) {
            jsonObject.put("success", true);
            jsonObject.put("message", "修改人员信息成功");
        } else {
            jsonObject.put("success", false);
            jsonObject.put("message", "修改人员信息失败");
        }
        return jsonObject.toJSONString();
    }

    @RequestMapping(value = "deletePerson", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String deletePerson(int id) {
        JSONObject jsonObject = new JSONObject();
        if (personService.deletePerson(id)) {
            jsonObject.put("success", true);
            jsonObject.put("message", "删除人员信息成功");
        } else {
            jsonObject.put("success", false);
            jsonObject.put("message", "删除人员信息失败");
        }
        return jsonObject.toJSONString();
    }
}
最近下载更多
whb5566  LV10 昨天
lingtiejing  LV15 4月12日
sun丶孙  LV8 4月7日
cxt hahaha  LV1 3月29日
夜起星河  LV8 2023年12月27日
panwill  LV5 2023年12月18日
skook7  LV2 2023年12月13日
oulingqiao  LV13 2023年12月10日
fff2003  LV6 2023年11月13日
最近浏览更多
whb5566  LV10 昨天
孙龙52  LV6 前天
HANCW  LV8 4月16日
lingtiejing  LV15 4月12日
zolscy  LV12 4月9日
sun丶孙  LV8 4月7日
cxt hahaha  LV1 3月29日
流水本无情  LV9 3月24日
小海脑洞大开  LV11 3月20日
2497180190 2月20日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友