package com.baidu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baidu.entity.User;
import com.baidu.service.IUserService;

@Controller
@RequestMapping(value="/user")
public class UserController {
	
	@Autowired
	private IUserService userService;
	
	/*@RequestMapping(value="/findAll")
	public String findAll(Model model){
		List<User> list = userService.findAllUser();
		
		model.addAttribute("userList", list);//request
		return "showUser";
	}*/
	
	
	@RequestMapping(value="/jsonFindAll")
	@ResponseBody
	public Map jsonFindAll(int page,int rows,String sort,String order){
		
		//查询总条数
		int total = userService.findUserTotalCount();
		//当前页记录
		List<User> list = userService.findAllUser(page,rows,sort,order);
		
		Map map = new HashMap();
		map.put("total", total);
		map.put("rows", list);
		
		return map;
	}
	
	
	
	
	@RequestMapping(value="/del")
	@ResponseBody
	public String del(int id){
		userService.delete(id);
		return "success";
	}
	
	//批量删除
	@RequestMapping(value="/dels")
	@ResponseBody
	public Map<String,String> del(String ids){
		Map<String,String> map = new HashMap<String,String>();
		System.out.println(ids);
		try {
			userService.delete(ids);
			map.put("result", "success");
			map.put("msg", "删除成功!");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			map.put("result", "fail");
			map.put("msg", "删除失败,您删除的用户被其数据约束,不能删除");
		}
		return map;
	}
	
	
	
	@RequestMapping(value="/add")
	@ResponseBody
	public String add(User user){
		user.setId(null);
		//user.setStatus(0);
		userService.add(user);
		return "success";
	}
	@RequestMapping(value="/update")
	@ResponseBody
	public String update(User user){
		//user.setId(null);
		//user.setStatus(0);
		userService.update(user);
		return "success";
	}
	
}
最近下载更多
wouldbb  LV6 2023年3月25日
yanghanqiang  LV3 2023年2月17日
1342203642  LV10 2023年1月18日
超炫爱  LV2 2022年12月5日
molu123456 2022年11月15日
暂无贡献等级
yazhiyjs  LV4 2022年8月30日
拂袖云中  LV4 2022年6月17日
微信网友_5916966536499200  LV2 2022年4月15日
wanglinddad  LV54 2022年3月24日
你好啊李光庚  LV1 2022年3月21日
最近浏览更多
123123123W  LV7 1月22日
空中飞尘  LV13 2023年12月13日
1383838438  LV1 2023年11月15日
微信网友_6465435620184064  LV6 2023年10月24日
asssasa  LV1 2023年10月17日
唐钰小宝A  LV13 2023年9月12日
山东老马 2023年7月7日
暂无贡献等级
2267068802 2023年6月12日
暂无贡献等级
Antuz56  LV2 2023年6月6日
0011100  LV12 2023年5月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友