cn.test.controller
UserController.java
package cn.test.controller;
import java.util.List;
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.RequestParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.test.po.Adminlogin;
import cn.test.po.User;
import cn.test.po.userlogin;
import cn.test.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
UserService userService;
@RequestMapping("/queryUserByUid")
public String queryUser(int uid, Model model) {
User u = userService.queryUserByUid(uid);
model.addAttribute("user", u);
return "updataUser";
}
@RequestMapping("/queryUserByName")
public String updateUser(String username, Model model) {
User u = userService.queryUserByName(username);
model.addAttribute("user", u);
return "updataUser2";
}
//锟斤拷锟斤拷员锟斤拷锟斤拷锟矫伙拷锟斤拷息
@RequestMapping("/queryByUname")
public String queryByUname(String username, Model model) {
List<User> u = userService.queryByUname(username);
model.addAttribute("user", u);
model.addAttribute("ulist", u);
return "admininfo";
}
@RequestMapping("/getAllUser")
public String getAllUser(Model model, @RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "4") int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<User> u = userService.getAllUser();
PageInfo<User> p = new PageInfo<User>(u);
model.addAttribute("ulist", u);
model.addAttribute("pageinfo", p);
model.addAttribute("flag", 1);
return "userinfo";
}
@RequestMapping("/getAllUser2")
public String getAllUser2(Model model, @RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "8") int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<User> u = userService.getAllUser();
PageInfo<User> p = new PageInfo<User>(u);
model.addAttribute("ulist", u);
model.addAttribute("pageinfo", p);
model.addAttribute("flag", 1);
return "admininfo";
}
@RequestMapping("/toAddUser")
public String toAddUser() {
return "addUser";
}
//锟斤拷锟斤拷没锟�
@RequestMapping("/addUser")
public String addUser(User user) {
int t = userService.addUser(user);
if (t > 0) {
return "forward:getAllUser2";
} else {
return "erro";
}
}
@RequestMapping("/deleteUser")
public String deleteUser(int uid) {
int t = userService.deleteUser(uid);
if (t > 0) {
return "forward:getAllUser2";
} else {
return "erro";
}
}
//锟斤拷锟斤拷员锟斤拷锟铰★拷锟斤拷息
@RequestMapping("/updataUser")
public String updataUser(User user) {
int t = userService.updataUser(user);
if (t > 0) {
return "forward:getAllUser2";
} else {
return "erro";
}
}
//锟矫伙拷锟斤拷锟斤拷锟斤拷息
@RequestMapping("/updataUser2")
public String updataUser2(User user) {
int t = userService.updataUser(user);
if (t > 0) {
return "forward:getAlluser";
} else {
return "erro";
}
}
//锟矫伙拷锟斤拷录
@RequestMapping("/findUserByName")
public String findUserByName(User user,Model model) {
User u=userService.findUserByName(user);
if(u != null){
model.addAttribute("username", u.getUsername());
model.addAttribute("user", u);
return "forward:getAllUser";
}else{
return "erro";
}
}
//锟斤拷锟斤拷员锟斤拷录
@RequestMapping("/findAdminByName")
public String findAdminByName(Adminlogin admin,Model model) {
Adminlogin u=userService.findAdminByName(admin);
if(u != null){
model.addAttribute("adminname", u.getAdminname());