首页>代码>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(); } }

csx123456 LV1
3月9日
oldfox LV19
2024年10月22日
y1214435276 LV9
2024年9月26日
微信网友_7134912998903808 LV15
2024年9月11日
Oxygeni LV6
2024年7月14日
计科一班 LV7
2024年6月18日
witge1 LV1
2024年6月17日
不正经的90后程序猿 LV1
2024年6月2日
加油干阳神 LV9
2024年5月21日
唐僧洗头爱飘柔 LV22
2024年5月10日

csx123456 LV1
3月9日
aaron2953 LV11
2月22日
haomc052829 LV4
2024年12月3日
15719908287 LV9
2024年11月4日
oldfox LV19
2024年10月22日
y1214435276 LV9
2024年9月26日
微信网友_7134912998903808 LV15
2024年9月11日
codecc
2024年9月7日
暂无贡献等级
shuilianbing LV6
2024年8月24日
微信网友_7110715404963840
2024年8月5日
暂无贡献等级