请问 :
下面这段代码如何测试:
@Autowired
private UserService userService;
public String login(String userName, String pwd, String code, HttpSession session, HttpServletResponse response) {
boolean b = userService.isLogin(userName, pwd);
User user = userService.getUser(userName);
if (user != null) {
session.setAttribute("user", user);
} else {
return "error";
}
if (!(code.equalsIgnoreCase(session.getAttribute("code").toString()))) {
return "errorcode";
}
if (b) {
logger.info("========登录成功 userName:{}", userName);
return "success";
} else {
logger.info("========登录失败 userName:{}", userName);
return "error";
}
}
我总是注入不进去,userService总是空的。谁有比较好的办法,分享一下。谢谢。