首页>代码>spring+spring Mvc+mybatis+layui实现数据表格的增删改查(纯layui实现)>/ssmlayui/src/main/java/controller/StudentController.java
package controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; import entity.student; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import service.IStudentService; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @Controller @RequestMapping("student") public class StudentController { @Autowired IStudentService studentService ; @RequestMapping("/find") @ResponseBody public Object students(HttpServletRequest request){ Map userMap = new HashMap(); // 当前页数 int page = Integer.parseInt(request.getParameter("page")); // 显示条数 int limit = Integer.parseInt(request.getParameter("limit")); //作为sql语句的限制条件 int start = limit * (page-1); // 查询出数据的总条数 int counts = studentService.studentCounts(); String id = request.getParameter("id"); if (id==null || id==""){ List<student> students = studentService.getAllStu(start,limit); userMap.put("code",0); userMap.put("msg","lay ui-Table数据绑定数据库"); userMap.put("count",counts); userMap.put("data",students); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(userMap)); return jsonObject; }else{ student student = new student(); student.setId(id); List<student> students = studentService.getStuById(student); userMap.put("code",0); userMap.put("msg","lay ui-Table数据绑定数据库"); userMap.put("count",students.size()); userMap.put("data",students); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(userMap)); return jsonObject; } } @RequestMapping("/delete") @ResponseBody public int deleteStudent(@RequestParam("id") String id){ System.out.println("删除操作"); return studentService.deleteStudent(id); } @RequestMapping("/batchDelete") @ResponseBody public int batchDeleteStudents(HttpServletRequest request){ String str = request.getParameter("str"); String a[] = str.split(","); String arr[] = new String[a.length]; for (int i = 0 ; i < a.length ; i++){ arr[i]=a[i]; } return studentService.batchDeleteStudent(arr); } @RequestMapping(value="/add",method = RequestMethod.POST) @ResponseBody public int addStudent(student stu){ System.out.println("新增操作"); return studentService.addStudent(stu); } @RequestMapping(value="/edit",method = RequestMethod.POST) @ResponseBody public int editStudent(student stu){ System.out.println("编辑操作"); return studentService.editStudentData(stu); } @RequestMapping("/main") public Object index(){ return "pages/handleResult"; } }
最近下载更多
sun丶孙 LV8
4月3日
gecongkai LV8
2023年6月22日
1257592068 LV6
2023年6月13日
微信网友_6260196253601792 LV7
2023年6月7日
111112222333312131 LV4
2022年12月9日
331376387 LV5
2022年12月2日
2511952410 LV9
2022年9月17日
ty5854 LV1
2022年9月12日
lvhongquan LV11
2022年5月4日
xytthy LV3
2022年4月17日
最近浏览更多
sun丶孙 LV8
4月3日
WBelong LV7
4月2日
flygrass LV12
3月28日
流水本无情 LV9
3月24日
cielaurbo LV2
2023年11月16日
黑 LV7
2023年8月21日
1748938504 LV2
2023年6月30日
gecongkai LV8
2023年6月22日
1257592068 LV6
2023年6月13日
微信网友_6260196253601792 LV7
2023年6月7日