首页>代码>spring+spring mvc+mybatis+jQuery实现简单增删改查>/message-MSI/src/main/java/com/zhn/controller/UserController.java
package com.zhn.controller; import java.util.List; import javax.annotation.Resource; import javax.security.sasl.SaslException; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.zhn.pojo.User; import com.zhn.service.UserService; import com.zhn.utils.JsonResult; @Controller @RequestMapping("/user") public class UserController { @Resource private UserService userServiceImpl; private User currentuser;//当前用户 //ajax回调函数返回登录页面 @RequestMapping("/indexUI") public String indexUI(){ return "show"; } //跳转更新页面 @RequestMapping("/toupdata") public String updta(){ return "updata"; } //跳转添加页面 @RequestMapping("/toadd") public String toadd(){ return "add"; } //权限管理跳转到登录页面 @RequestMapping("/tologin") public String toLogin(){ return "login"; } //查询总用户数 @RequestMapping("/selectPage") @ResponseBody public JsonResult selectPage(){ Integer page=new Integer(userServiceImpl.selectPage()); return new JsonResult(page); } //查询用户名字总数 @RequestMapping("selectAllName") @ResponseBody public JsonResult selectAllName(){ List<String> allName=userServiceImpl.selectAllName(); return new JsonResult(allName); } //根据名字寻找用户 @RequestMapping("/selectByName") @ResponseBody public JsonResult selectByName(String name){ List<User> user=userServiceImpl.selectByName(name); return new JsonResult(user); } //添加用户 @RequestMapping(value="/addUser",method=RequestMethod.GET) @ResponseBody public JsonResult addUser(User user){ System.out.println(user.getName()); if(user.getName()!=""&&user.getPassword()!=""){ userServiceImpl.saveUser(user); } return new JsonResult("OK"); } //保存修改数据 @RequestMapping(value = "/updateUser", method=RequestMethod.GET) @ResponseBody public JsonResult UpdateUser( User user){ System.out.println(user.getPassword()); userServiceImpl.updateUser(user); return new JsonResult("OK"); } //根据Id寻找用户 @RequestMapping("/getUser") @ResponseBody public JsonResult getUser(int id){ currentuser=userServiceImpl.findById(id); return new JsonResult(currentuser); } //删除用户 @RequestMapping("/deleteUser") public String deleteUser(int id){ userServiceImpl.deleteUser(id); return "redirect:/user/indexUI.action"; } //加载页面用户 @RequestMapping("/list") @ResponseBody public JsonResult userList(Model model,int pageStart,int pageEnd){ List<User> userList=null; if(currentuser!=null){ userList = userServiceImpl.selectByList(pageStart,pageEnd); return new JsonResult(userList); }else return new JsonResult(userList); } @RequestMapping(value="/login", method=RequestMethod.POST) @ResponseBody public JsonResult login(String name, String password) { currentuser = userServiceImpl.findByUsername(name); if (currentuser == null || !password.equals(currentuser.getPassword())) { return new JsonResult(new SaslException("用户不存在")); } else { return new JsonResult("login ok"); } } }

oulingqiao LV13
2024年1月11日
李亮 LV19
2023年8月29日
十分士大夫1123 LV1
2023年8月14日
gecongkai LV8
2023年6月22日
惺惺惜xxxx LV1
2023年6月8日
斧头帮副帮主 LV5
2023年4月2日
云龙123456 LV7
2023年2月21日
jzh20020707 LV2
2022年12月16日
ZSY6699 LV4
2022年7月20日
and123456 LV11
2022年7月15日

xiaoaitx LV8
1月1日
微信网友_7316199114199040
2024年12月28日
暂无贡献等级
ma406805131 LV19
2024年6月18日
qq970040477 LV24
2024年6月16日
xin xie LV1
2024年6月13日
nurgul LV1
2024年6月8日
yuanyuan23 LV1
2024年5月30日
李俊雄 LV3
2024年5月8日
h G24741 LV2
2024年3月12日
oulingqiao LV13
2024年1月11日