47 lines
1.3 KiB
Java
47 lines
1.3 KiB
Java
|
package com.controller;
|
||
|
|
||
|
import com.domain.Role;
|
||
|
import com.service.RoleService;
|
||
|
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 java.util.List;
|
||
|
|
||
|
@RequestMapping("/role")
|
||
|
@Controller
|
||
|
public class RoleController {
|
||
|
|
||
|
|
||
|
// @Qualifier("roleService")
|
||
|
@Autowired
|
||
|
RoleService roleService;
|
||
|
|
||
|
@RequestMapping("/save")
|
||
|
public String save(Role role){
|
||
|
roleService.save(role);
|
||
|
return "redirect:/role/list";
|
||
|
}
|
||
|
|
||
|
@RequestMapping("/list")
|
||
|
public ModelAndView list(){
|
||
|
ModelAndView modelAndView = new ModelAndView();
|
||
|
List<Role> roleList = roleService.list();
|
||
|
//设置模型
|
||
|
modelAndView.addObject("roleList",roleList);
|
||
|
//设置视图
|
||
|
modelAndView.setViewName("role-list");
|
||
|
System.out.println(roleList);
|
||
|
return modelAndView;
|
||
|
}
|
||
|
@RequestMapping("/del/{roleId}")
|
||
|
public String del(@PathVariable("roleId") Long roleId){
|
||
|
roleService.del(roleId);
|
||
|
return "redirect:/role/list";
|
||
|
}
|
||
|
|
||
|
}
|