首页>代码>Spring mvc+jdbc+jstl分页,ajax开发的java web酒店管理系统,适合入门>/新建文件夹 (2)/jiudianguanli/src/com/bdnq/controller/UserController.java
package com.bdnq.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

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 com.bdnq.dao.UserDao;
import com.bdnq.dao.impl.UserDaoImpl;
import com.bdnq.entity.User;
import com.bdnq.service.UserService;
import com.bdnq.util.PageResult;

@Controller
@RequestMapping("/user")
public class UserController {
	
	public static String uid;
	
	@Autowired 
	private UserService userService;
	
	private UserDao userDao = new UserDaoImpl();
	
	@RequestMapping("/login")
	public String login(String username,String password){
		User user=userService.login(username, password);
		System.out.println(username);
		System.out.println(password);
		uid = user.getUserid();
		System.out.println(username);
		String zhiwei = user.getRenyuan();
		if(zhiwei.equals("管理员")){
			return "redirect:getAllUser";
		}else if(zhiwei.equals("前台人员")){
			return "redirect:/fangjian/getAllfj";
		}else if(zhiwei.equals("清洁人员")){
			return "redirect:/fangjianfuwu/getQingLi";
		}else{
			return "login";
		}
	}
	
	@RequestMapping("/getAllUser")
	public String getAllUser(String pageNo,HttpServletRequest request){
		
		int pageNo1 = 1;
		int pageSize = 10;
		String pageNOStr = null;
		try {
			pageNOStr = new String(pageNo.getBytes("ISO-8859-1"),"UTF-8");
		} catch (Exception e) {
			// TODO: handle exception
		}
		if(pageNOStr != null){
			pageNo1 = Integer.valueOf(pageNo).intValue();
		}
		
		List<User> list  = userService.getAllUser(pageNo1, pageSize);
		int count = userService.Count() ;
		int pageCount = 0;
		
		if(count % pageSize == 0)
			pageCount = count / pageSize;
		else
			pageCount = count / pageSize + 1;
		
		
		
		
		PageResult<User> pageResult = new PageResult<User>();
		pageResult.setPageNo(pageNo1);
		pageResult.setPageSize(pageSize);
		pageResult.setCount(count);
		pageResult.setPageCount(pageCount);
		pageResult.setResults(list);
		pageResult.setA(-1);
		request.setAttribute("listUser", pageResult);
		return "getAllUser";
	}
	
	@RequestMapping("/getUsername")
	public String getUsername( String getUsername ,String pageNo,String name,HttpServletRequest request) {
		String username = null;
		String nn = null;
		
		if (name!=null) {
			try {
				nn = new String(name.getBytes("ISO-8859-1"),"UTF-8");
				System.out.println(new String(name.getBytes("ISO-8859-1"),"UTF-8"));
			} catch (Exception e) {
				// TODO: handle exception
			}
			
		}
		if (nn==null) {
			if (getUsername==null) {
				return "redirect:getAllUser";
			}
			try {
				System.out.println(new String(request.getParameter("getUsername").getBytes("ISO-8859-1"),"UTF-8"));
				username = new String(request.getParameter("getUsername").getBytes("ISO-8859-1"),"UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (username==null) {
				System.out.println("��ת");
				return "redirect:getAllUser";
			}
		}
		String x = null;
		if (nn==null) {
			x = username;
			
		}else if (username==null) {
			x = nn;
		}
		
		
		int pageNo1 = 1;
		int pageSize = 10;
		String pageNOStr = null;
		try {
			pageNOStr = new String(request.getParameter("pageNo").getBytes("ISO-8859-1"),"UTF-8");
		} catch (Exception e) {
			// TODO: handle exception
		}
		if(pageNOStr != null){
			pageNo1 = Integer.parseInt(pageNOStr);
		}
		List<User> list  = userService.getUsername(x, pageNo1,pageSize);
		int count = userService.getNameCount(x) ;
		int pageCount = 0;
		
		if(count % pageSize == 0)
			pageCount = count / pageSize;
		else
			pageCount = count / pageSize + 1;
		
		
		PageResult<User> pageResult = new PageResult<User>();
		pageResult.setPageNo(pageNo1);
		pageResult.setPageSize(pageSize);
		pageResult.setCount(count);
		pageResult.setPageCount(pageCount);
		pageResult.setResults(list);
		pageResult.setName(x);
		pageResult.setA(1);
		
		request.setAttribute("listUser", pageResult);
		return "getAllUser";
	}
	
	@RequestMapping("/getUserById")
	public String getUserById(String userid,HttpServletRequest request){
		User user = userService.getUserById(userid);
		System.out.println(user.getUsername());
		request.setAttribute("user", user);
		return "updataUser";
	}
	
	@RequestMapping("/updataUser")
	public String updataUser(HttpServletRequest request){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println(request.getParameter("userid"));
		String x  = null;
		String xxz  = null;
		String xxx  = null;
		String xxxx  = null;
		String xxxxx  = null;
		String xxxxxx  = null;
		String xxxxxxx  = null;
		String xxxxxxxx  = null;
		try {
			 x = new String(request.getParameter("userid").getBytes("ISO-8859-1"),"UTF-8");
			 xxz = new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8");
			 xxx = new String(request.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
			 xxxx = new String(request.getParameter("gangwei").getBytes("ISO-8859-1"),"UTF-8");
			 xxxxx = new String(request.getParameter("dianhua").getBytes("ISO-8859-1"),"UTF-8");
			 xxxxxx = new String(request.getParameter("shenfenzheng").getBytes("ISO-8859-1"),"UTF-8");
			 xxxxxxx = new String(request.getParameter("weixin").getBytes("ISO-8859-1"),"UTF-8");
			 xxxxxxxx = new String(request.getParameter("QQ").getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		System.out.println(x+"=========="+xxz+"============="+xxx);
		Integer xx = Integer.getInteger(x);
		User user = new User();
		user.setUsername(xxz);
		user.setUserid(request.getParameter("userid"));
		user.setPassword(xxx);
		user.setRenyuan(xxxx);
		user.setDianhua(xxxxx);
		user.setShenfenzheng(xxxxxx);
		user.setWeixin(xxxxxxx);
		user.setQQ(xxxxxxxx);
		int rows = userService.updataUser(user);
		if (rows>0) {
			System.out.println("修改成功");
		}
		return "redirect:getAllUser";
	}
	
	@RequestMapping("/deleteUser")
	public String deleteUser(HttpServletRequest request){
		String userIdStr = request.getParameter("userid");
		int userId = Integer.parseInt(userIdStr);
		
		int rows = userService.deleteUser(userId);
		if (rows>0) {
			System.out.println("删除成功");
			return "1";
		}else{
			System.out.println("删除失败");
			return "0";
		}
	}
	
	@RequestMapping("/insertUser")
	public String insertUser(HttpServletRequest request){
		System.out.println(request.getParameter("username")+"ss"+request.getParameter("shenfenzhenghao")+"ss"
				+request.getParameter("dianhua")+"ss"+request.getParameter("renyuan")+"ss"+request.getParameter("password")+"ss"+
				request.getParameter("weixin")+"ss"+request.getParameter("qq"));
		User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setShenfenzheng(request.getParameter("shenfenzhenghao"));
		user.setDianhua(request.getParameter("dianhua"));
		user.setRenyuan(request.getParameter("gangwei"));
		user.setPassword(request.getParameter("password"));
		user.setWeixin(request.getParameter("weixin"));
		user.setQQ(request.getParameter("qq"));
		int rows = userDao.insertUser(user);
		if (rows>0) {
			System.out.println("增加成功!!!");
		} else {
			System.out.println("增加失败!!!");
		}
		 return "redirect:getAllUser";
	}
	
	@RequestMapping("/zengjiaUser")
	public String zengjiaUser(HttpServletRequest request){
		User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setShenfenzheng(request.getParameter("shenfenzhenghao"));
		user.setDianhua(request.getParameter("dianhua"));
		user.setRenyuan(null);
		user.setPassword(null);
		user.setWeixin(request.getParameter("weixin"));
		user.setQQ(request.getParameter("qq"));
		int rows = userDao.insertUser(user);
		if (rows>0) {
			System.out.println("增加成功!!!");
		} else {
			System.out.println("增加失败!!!");
		}
		 return "redirect:/fangjian/getAllfj";
	}
}
最近下载更多
颜菜菜  LV2 2023年12月23日
214109  LV2 2022年12月9日
微信网友_6248713511227392  LV11 2022年12月5日
最代码-宋家辉  LV61 2022年6月23日
user123qyb  LV1 2022年5月17日
xk16675552250  LV33 2022年3月31日
程序员阿莱  LV2 2021年11月23日
小火火  LV7 2021年10月4日
famloliy  LV6 2021年8月23日
康日澜  LV9 2021年6月26日
最近浏览更多
xiao小果  LV13 8月27日
TY0165  LV20 6月24日
1827129306e  LV1 5月27日
pokerf  LV5 4月26日
yeanan  LV1 3月28日
heshao  LV2 1月11日
颜菜菜  LV2 2023年12月23日
yolo_light  LV1 2023年12月21日
wdw2444156008 2023年10月31日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友