1. MemberVO
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MemberVO {
private String email;
private String pw;
private String phone;
private String address;
}
2. DAO
import java.util.ArrayList;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.smhrd.database.SqlSessionManager;
public class DAO {
private SqlSessionFactory sqlSessionFactory = SqlSessionManager.getSqlSession();
private SqlSession sqlSession = null;
public int join(MemberVO vo) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.insert("com.smhrd.model.DAO.memberinsert", vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
public MemberVO Login(MemberVO vo) {
MemberVO result = null;
try {
sqlSession = sqlSessionFactory.openSession(true);
result = sqlSession.selectOne("com.smhrd.model.DAO.memberLogin", vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return result;
}
public int Update(MemberVO vo) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.update("com.smhrd.model.DAO.memberUpdate", vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public ArrayList<MemberVO> showMember() {
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
sqlSession = sqlSessionFactory.openSession(true);
list = (ArrayList) sqlSession.selectList("com.smhrd.model.DAO.memberSelect");
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return list;
}
public int delete(String email) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.delete("com.smhrd.model.DAO.memberDelete", email);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
}
3. BoardVO
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@AllArgsConstructor // 모든변수
@NoArgsConstructor // 기본생성자
@Getter
@Setter
@RequiredArgsConstructor // 원하는 변수 생성자
public class BoardVO {
private int num;
@NonNull
private String title;
@NonNull
private String writer;
@NonNull
private String filename;
@NonNull
private String content;
private String b_day;
}
4.BoardDAO
import java.util.ArrayList;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.smhrd.database.SqlSessionManager;
public class BoardDAO {
private SqlSessionFactory sqlSessionFactory = SqlSessionManager.getSqlSession();
private SqlSession sqlSession = null;
public int upload(BoardVO vo) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.insert("com.smhrd.model.BoardDAO.boardInsert", vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
public ArrayList<BoardVO> showBoard() {
ArrayList<BoardVO> list = new ArrayList<BoardVO>();
try {
sqlSession = sqlSessionFactory.openSession(true);
list = (ArrayList) sqlSession.selectList("com.smhrd.model.BoardDAO.boardSelect");
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return list;
}
public BoardVO showDetail(int num) {
BoardVO vo = new BoardVO();
try {
sqlSession = sqlSessionFactory.openSession(true);
vo = sqlSession.selectOne("com.smhrd.model.BoardDAO.boarddetail", num);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return vo;
}
public int delete(String num) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.delete("com.smhrd.model.BoardDAO.boarddelete", num);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
}
'BACK-END > JSP Servlet' 카테고리의 다른 글
[MessageSystem]Controller_Class (0) | 2022.07.15 |
---|---|
[MessageSystem]DataBase (0) | 2022.07.15 |
[MessageSystem]ViewBoard.jsp (0) | 2022.07.15 |
[MessageSystem]WriterBoard.jsp (0) | 2022.07.15 |
[MessageSystem]BoardMain.jsp (0) | 2022.07.15 |