我正在尝试通过他们的 id 检索用户,并在页面上检索分配给他们的模块。我已经映射了模型中的一对多关系。
用户模型
@Entity
@Table(name = "user")
@Component
public class User implements Serializable
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="user")
private Set<Module> sModule = new HashSet<Module>();
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="manager")
private Set<Module> cModule = new HashSet<Module>();
模块型号
@Entity
@Table(name = "modules")
@Component
public class Module implements Serializable
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="user_id", insertable=false, updatable=false)
private User user;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="manager_id", insertable=false, updatable=false)
private User manager;
它的控制器 -
@RequestMapping(value="/home/user_page/{userId}", method =
RequestMethod.GET)
public String showUserModules(@PathVariable("userId") String userId, ModelMap
map, HttpServletRequest request) {
map.addAttribute("cp", request.getContextPath());
map.addAttribute("user", userService.getWithModules(userId));
return "/home/user_page";}
当我尝试打开 user_page 时,它返回一个错误,显示:
The requested resource is not available
那么,当我访问他们的用户页面时,如何获取用户和他们所需的模块。
编辑:堆栈跟踪
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP
request with URI [/professional/home/user_page] in DispatcherServlet
with name 'servlet-context'