首页>代码>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 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日
最近浏览更多
h G24741  LV2 3月12日
oulingqiao  LV13 1月11日
wwwww816  LV3 2023年12月19日
李亮  LV19 2023年8月29日
 LV7 2023年8月21日
十分士大夫1123  LV1 2023年8月14日
fuyouou  LV5 2023年7月5日
gecongkai  LV8 2023年6月22日
faye123 2023年6月19日
暂无贡献等级
19137715150  LV1 2023年6月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友