Spring MVC JdbcTemplate 질문
-
게시물 수정 , 삭제는 로그인 필요
login 로직 연습을 하고 있습니다. db는 JdbcTemplate를 사용하고 있으나
쿼리문은
private static String LOGIN_USER = "SELECT * FROM USERS WHERE ID = ? AND PASSWORD = ?";
public UserVO login_user(UserVO vo){
Object[] args = {vo.getId(),vo.getPassword()};
return jdbcTemplate.queryForObject(LOGIN_USER,args,new UserRowMapper());
}
class UserRowMapper implements RowMapper<UserVO>{
public UserVO mapRow(ResultSet resultSet, int i) throws SQLException {
UserVO vo = new UserVO();
vo.setId(resultSet.getString("id"));
vo.setPassword(resultSet.getString("password"));
vo.setName(resultSet.getString("name"));
vo.setRole(resultSet.getString("role"));
return vo;
}
}
여기에서 유저의 id와 비밀번호를 받고 jdbcTemplate.queryForObject를 실행시켰을경우 query문이
맞을때는 제대로 넘어가는데 만약 아이디와 비밀번호가 틀렸을 경우에 user객체를 받지도 못하고 그냥 멈춥니다. 즉 로그인이 못하면 login.jsp 로 넘어가야하는데 그 부분이 실행이 되지 않습니다. 이때 어떤식으로
jdbcTemplate를 사용해야 할까요?
로그인 컨트롤러 코드입니다.
package com.springbook.biz.User.view;
import com.springbook.biz.User.UserVO;
import com.springbook.biz.User.impl.UserService;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Login_Controller implements Controller{
public String handler(HttpServletRequest request, HttpServletResponse response) {
UserVO vo = new UserVO();
UserVO user = new UserVO();
String id = request.getParameter("id");
String password = request.getParameter("password");
vo.setId(id);
vo.setPassword(password);
AbstractApplicationContext container = new GenericXmlApplicationContext("applicationContext.xml");
UserService service = (UserService)container.getBean("userService");
user = service.login_user(vo);
String viewName = null;
if(user != null){
viewName = "getBoardList";
}else{
viewName = "login";
}
return viewName;
}
}
쿼리문은
private static String LOGIN_USER = "SELECT * FROM USERS WHERE ID = ? AND PASSWORD = ?";
public UserVO login_user(UserVO vo){
Object[] args = {vo.getId(),vo.getPassword()};
return jdbcTemplate.queryForObject(LOGIN_USER,args,new UserRowMapper());
}
class UserRowMapper implements RowMapper<UserVO>{
public UserVO mapRow(ResultSet resultSet, int i) throws SQLException {
UserVO vo = new UserVO();
vo.setId(resultSet.getString("id"));
vo.setPassword(resultSet.getString("password"));
vo.setName(resultSet.getString("name"));
vo.setRole(resultSet.getString("role"));
return vo;
}
}
여기에서 유저의 id와 비밀번호를 받고 jdbcTemplate.queryForObject를 실행시켰을경우 query문이
맞을때는 제대로 넘어가는데 만약 아이디와 비밀번호가 틀렸을 경우에 user객체를 받지도 못하고 그냥 멈춥니다. 즉 로그인이 못하면 login.jsp 로 넘어가야하는데 그 부분이 실행이 되지 않습니다. 이때 어떤식으로
jdbcTemplate를 사용해야 할까요?
로그인 컨트롤러 코드입니다.
package com.springbook.biz.User.view;
import com.springbook.biz.User.UserVO;
import com.springbook.biz.User.impl.UserService;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Login_Controller implements Controller{
public String handler(HttpServletRequest request, HttpServletResponse response) {
UserVO vo = new UserVO();
UserVO user = new UserVO();
String id = request.getParameter("id");
String password = request.getParameter("password");
vo.setId(id);
vo.setPassword(password);
AbstractApplicationContext container = new GenericXmlApplicationContext("applicationContext.xml");
UserService service = (UserService)container.getBean("userService");
user = service.login_user(vo);
String viewName = null;
if(user != null){
viewName = "getBoardList";
}else{
viewName = "login";
}
return viewName;
}
}
#spring mvc #spring mvc project 없음 #spring mvc 구조 #spring mvc 패턴이란 #spring mvc project #spring mvc 프로젝트 생성 #spring mvc project 생성 #spring mvc found on classpath which is incompatible with spring cloud gateway #spring mvc란 #spring mvc coroutine