真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Spring注入Bean時為null

Spring.xml

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作和成都移動服務(wù)器托管的網(wǎng)絡(luò)公司,有著豐富的建站經(jīng)驗(yàn)和案例。

jdbc.properties

driver=com.MySQL.jdbc.Driver

url=jdbc:mysql://127.0.0.1:3306/xmscode?useUnicode=true&characterEncoding=utf8

user=root

password=1234

controller:

@Controller

@RequestMapping("login")

public class LoginController {

private LoginService loginService;

public LoginService getLoginService() {

return loginService;

}

public void setLoginService(LoginService loginService) {

this.loginService = loginService;

}

@RequestMapping("tologin")

public String toLogin(){

return "login";

}

@RequestMapping("login")

public String login(User user, HttpServletRequest request) throws Exception{

//該行報錯   loginService為null

                User u = loginService.checkInfo(user);

HttpSession session = request.getSession();

session.setAttribute("nickname", u.getNickname());

return "index";

}

}

dao接口:

public interface LoginDao {

//根據(jù)email查找User

public User findUserByEmail(User user) throws Exception;

}

daoImpl:

@Repository

public class LoginDaoImpl implements LoginDao {

private JdbcTemplate jdbcTemplate;

public JdbcTemplate getJdbcTemplate() {

return jdbcTemplate;

}


public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {

this.jdbcTemplate = jdbcTemplate;

}


public User findUserByEmail(User user) throws Exception {

User u = null;

String sql = "select * from xc_user where email=?";

Object[] params = new Object[]{user.getEmail()};

u = jdbcTemplate.queryForObject(sql, (RowMapper) new User(), params);

return u;

}

}

service接口:

@Service

public interface LoginService {

public User checkInfo(User user) throws Exception;

}

service實(shí)現(xiàn)類:

@Service

public class loginServiceImpl implements LoginService{


private LoginDao loginDao;

public LoginDao getLoginDao() {

return loginDao;

}


public void setLoginDao(LoginDao loginDao) {

this.loginDao = loginDao;

}


public User checkInfo(User user) throws Exception{

System.out.println("loginDao"+loginDao);

User u = null;

u = loginDao.findUserByEmail(user);

if(u==null){

//用戶名錯誤

throw new EmailErrorException("用戶名錯誤");

}else if(!u.getPassword().equals(user.getPassword())){

//密碼錯誤

throw new PasswordErrorException("密碼錯誤");

}else{

//用戶名和密碼正確

return u;

}

}

}


網(wǎng)頁標(biāo)題:Spring注入Bean時為null
當(dāng)前鏈接:http://weahome.cn/article/jgcjjc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部