首页>代码>ssm+easyui实现学生信息增删改查及分页查询,搜索简单实例>/ssm_easyui/src/main/java/com/liu/controller/StudentsController.java
package com.liu.controller;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.liu.pojo.EasyUIDatagrid;
import com.liu.pojo.Students;
import com.liu.service.StudentsService;
@Controller
@RequestMapping("page")
public class StudentsController {
@Autowired
private StudentsService rolesService;
@ResponseBody
@RequestMapping("/showStu")
//参数名必须是rows,page否则分页无效果
public EasyUIDatagrid show( @RequestParam(defaultValue="2")int rows,@RequestParam(defaultValue="1")int page){
return rolesService.show(rows, page);
}
@ResponseBody
@RequestMapping("/update")
public int update(Students stu) {
//System.out.println("------"+stu);
return rolesService.updateStu(stu);
}
@ResponseBody
@RequestMapping("/add")
public int add(Students stu) {
System.out.println("----------"+stu);
return rolesService.insStu(stu);
}
@ResponseBody
@RequestMapping("/remove")
public int remove(HttpServletRequest req,int id) {
return rolesService.deleteStu(id);
}
@ResponseBody
@RequestMapping("/removeAll")
public int removeAll(HttpServletRequest req,@RequestParam("ids") int[] ids) {
//System.out.println("-----------id---"+ids);
for (int i : ids) {
rolesService.deleteStu(i);
}
return 1;
}
@ResponseBody
@RequestMapping("/nquery")
public Map<String,Object> queryByName(String stuname) {
try {
Map<String,Object> map = new HashMap<String, Object>();
List<Students> list = rolesService.queryUserByName(stuname);
//System.out.println("--------list------"+stuname+"------"+list);
map.put("total", list.size());
map.put("rows", list);
//System.out.println(map);
return map;
} catch (Exception e) {
return null;
}
}
@ResponseBody
@RequestMapping(value = "/idquery")
public Map<String,Object> query(@RequestParam("stuSort")int stuSort) {
try {
Map<String,Object> map = new HashMap<String, Object>();
//System.out.println("-------------"+stuSort);
Students user = rolesService.queryStuBySort(stuSort);
List<Students> list = new LinkedList<Students>();
list.add(user);
map.put("total","1");
map.put("rows", list);
//System.out.println(map);
return map;
} catch (Exception e) {
return null;
}
}
}
最近下载更多
hongdongdong LV14
2024年6月17日
沈从文 LV3
2024年1月1日
aaa5849310 LV25
2022年3月10日
543666826 LV34
2021年11月20日
Gxb001020 LV10
2021年6月18日
酒后少年 LV6
2021年5月15日
liuxie LV12
2021年4月16日
hdf999 LV12
2021年4月3日
张先生1121 LV3
2021年1月11日
snowing_for LV9
2020年9月16日
最近浏览更多
超级无敌神圣大帅比 LV1
3月28日
LZPCJM LV1
2024年11月19日
wanderingsoul LV2
2024年6月15日
xin xie LV1
2024年6月13日
hongdongdong LV14
2024年6月12日
szwanx
2024年5月18日
暂无贡献等级
沈从文 LV3
2023年12月31日
微信网友_6802139027345408 LV2
2023年12月31日
taoshen95 LV16
2023年12月25日
wwwww816 LV5
2023年12月19日

