package com.controller; import com.domain.Role; import com.domain.User; import com.service.RoleService; import com.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpSession; import java.util.List; @Controller @RequestMapping("/user") public class UserController { @Autowired //@Qualifier("userService") private UserService userService; @Autowired //@Qualifier("roleService") private RoleService roleService; @RequestMapping("/login") public String login(String username, String password, HttpSession session){ User user=userService.login(username,password); if(user!=null){ session.setAttribute("user",user); return "redirect:/index.jsp"; }else{ return "redirect:/login.jsp"; } } @RequestMapping("/del/{userId}") public String del(@PathVariable("userId") Long userId){ userService.del(userId); return "redirect:/user/list"; } @RequestMapping("/save") public String save(User user,Long[] roleIds){ userService.save(user,roleIds); return "redirect:/user/list"; } @RequestMapping("/saveUI") public ModelAndView saveUI(){ ModelAndView modelAndView = new ModelAndView(); List roleList = roleService.list(); modelAndView.addObject("roleList",roleList); modelAndView.setViewName("user-add"); return modelAndView; } @RequestMapping("/list") public ModelAndView list(){ List userList = userService.list(); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("userList",userList); modelAndView.setViewName("user-list"); return modelAndView; } }