我的代码:
@Controller
@RequestMapping(value = "/register")
public class RegisterController {
@RequestMapping(method = RequestMethod.GET)
public String viewRegistration(Map<String, Object> model) {
User userForm = new User();
model.put("userForm", userForm);
List<String> professionList = new ArrayList<>();
professionList.add("Developer");
professionList.add("Designer");
professionList.add("IT Manager");
model.put("professionList", professionList);
return "Registration";
}
}
我得到的错误:
WARNING: No mapping found for HTTP request with URI [/SpringSecurity/register] in DispatcherServlet with name 'dispatcher'
在另一个班级我有这样的代码:
@RequestMapping(value = "/admin**", method = RequestMethod.GET)
public ModelAndView adminPage() {
ModelAndView model = new ModelAndView();
model.addObject("title", "Spring Security Login Form - Database Authentication");
model.addObject("message", "This page is for ROLE_ADMIN only!");
model.setViewName("admin");
return model;
}
它有效。
我知道它的方法有点不同,但有什么不同以至于它不起作用?
答案 0 :(得分:0)
我只需将它放入正确的包中。
我有一行应用配置:
@ComponentScan({ "org.maguss.*" })
它定义了应该弹出的包。由于我将Controller
放在另一个包中,因此没有将其考虑在内。