ORM(Object Relation Mapping)
ORM을 사용하지 않은 코드
public void insertUser(UserVO userVO){
String query="INSERT INTO USER(EMAIL, NAME, PW)" + " VALUES(?, ?, ?)";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setString (1, userVO.getEmail());
preparedStmt.setString (2, userVO.getName());
preparedStmt.setString (3, userVO.getPW());
// execute the preparedstatement
preparedStmt.execute();
}
ex) MyBatis를 적용한 코드
public class UserDAO {
@Autowired
private SqlSession sqlSession;
private final String namespace = "mang.blog.user.userMapper.";
public int insertUser(UserVO userVO) {
return sqlSession.insert(namespace+"insertUser", userVO);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mang.blog.user.userMapper">
<insert id="insertUser" parameterType = "userVO">
INSERT USER(
EMAIL, USER_NAME, USER_PW,
)VALUES(
#{userEmail}, #{userName}, #{userPw}
)
</insert>
</mapper>