package com.ajxm.web.controller; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.ajxm.web.entity.User; import com.ajxm.web.service.IUserService; @Controller @RequestMapping(value = "/user") public class UserController { @Resource(name = "userService") IUserService userService; public void setUserService(IUserService userService) { this.userService = userService; } @RequestMapping(value = "/login", method = RequestMethod.POST) public String login(String uname,String password,RedirectAttributes rediect) { try { User result = userService.login(uname, password); rediect.addFlashAttribute("user", result); return "redirect:/main"; } catch (Exception e) { return "errors/500"; } } @RequestMapping(value = "/register", method = RequestMethod.POST) @ResponseBody public String register(User user) { try { userService.insertUser(user); return "{\"code\":\"success\"}"; } catch (Exception e) { return "{\"code\":\"error\"}"; } } @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public String delete(String userid) { try { userService.deleteUser(userid); return "{\"code\":\"success\"}"; } catch (Exception e) { return "{\"code\":\"error\"}"; } } @RequestMapping(value = "/update", method = RequestMethod.POST) @ResponseBody public String update(User user) { try { userService.updateUser(user); return "{\"code\":\"success\"}"; } catch (Exception e) { return "{\"code\":\"error\"}"; } } @RequestMapping(value = "/idquery", method = RequestMethod.POST) @ResponseBody public Map<String,Object> query(String userid) { try { Map<String,Object> map = new HashMap<String, Object>(); User user = userService.queryUserById(userid); List<User> list = new LinkedList<User>(); list.add(user); map.put("total","1"); map.put("rows", list); return map; } catch (Exception e) { return null; } } @RequestMapping(value = "/nquery", method = RequestMethod.POST) @ResponseBody public Map<String,Object> queryByName(String nickname) { try { Map<String,Object> map = new HashMap<String, Object>(); List<User> list = userService.queryUserByName(nickname); map.put("total", list.size()); map.put("rows", list); return map; } catch (Exception e) { return null; } } @RequestMapping(value = "/list", method = RequestMethod.POST) @ResponseBody public List<User> getList() { try { return userService.getList(); } catch (Exception e) { return null; } } @RequestMapping(value = "/page", method = RequestMethod.POST) @ResponseBody public Map<String, Object> getPageList(int index, int size) { Map<String, Object> map = new HashMap<String, Object>(); try { List<User> list = userService.getPageList(index, size); map.put("total", "14");//这里设置固定为14,是因为测试的时候只有14条数据,这里可以是为了方便 map.put("rows", list); } catch (Exception e) { map.put("total", 0); map.put("rows", null); } return map; } }

yeyuuu LV6
2023年5月20日
h_z_feng LV1
2022年12月24日
potato1234 LV6
2022年3月22日
amour1 LV11
2021年12月5日
543666826 LV34
2021年11月19日
w384553037 LV1
2021年11月4日
wubinbin LV11
2021年10月10日
heqian LV17
2021年9月28日
ljl123456321 LV1
2021年9月11日
木木不爱安妮酱 LV10
2021年7月3日