MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค JSP

[JSP] mvc2 (+mybatis) ์ด์ •๋ฆฌ

HYEJU01 2024. 7. 17. 23:24

 

MVC ํŒจํ„ด

 

๐Ÿ‘จ‍๐Ÿ’ผ :  MVC ํŒจํ„ด์ด๋ž€?

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค ๋•Œ ์„ค๊ณ„๋ฐฉ์‹ ์ •๋„๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋˜๊ฒ ๋‹ค.

 

๐Ÿ‘จ‍๐Ÿ’ผ :  ์—ฌ๊ธฐ์„œ MVC2 ๋ž€,

๋ชจ๋ธ(Model), ๋ทฐ(View), ์ปจํŠธ๋กค๋Ÿฌ(Controller)๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๋” ํšจ์œจ์ ์œผ๋กœ ๊ตฌ์กฐํ™”ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

 

๋ทฐ(View)๊ฐ€ HTML/CSS/JavaScript๋กœ ๊ตฌ์„ฑ๋œ ์›น ํŽ˜์ด์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๊ณ ,

๋ชจ๋ธ(Model)์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๋ฉฐ,

์ปจํŠธ๋กค๋Ÿฌ(Controller)๊ฐ€ ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ์ ์ ˆํ•œ ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :  MVC2 ์˜ ์ „๋ฐ˜์ ์ธ ํ๋ฆ„์€

Client โ–ถ Controller โ–ถ Service โ–ถDAO โ–ถ DTO โ–ถ DB

 

 


์„œ๋ธ”๋ฆฟ Servlet / ์ปจํŠธ๋กค๋Ÿฌ Controller

๐Ÿ‘จ‍๐Ÿ’ผ :  ํ•˜๋‚˜์”ฉ ์•Œ์•„๋ณด๋„๋ก ํ•˜์ž.

๋จผ์ € Client ๊ฐ€ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด

๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋ชจ๋“  ์š”์ฒญ์€ Controller๋ฅผ ๊ฑฐ์น˜๊ฒŒ ๋œ๋‹ค. (์š”์ฒญ ๋ถ„๊ธฐ)

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :  ์—ฌ๊ธฐ์„œ ๋จผ์ €, ์„œ๋ธ”๋ฆฟ์„ ์•Œ์•„์•ผํ•˜๋Š”๋ฐ

์„œ๋ธ”๋ฆฟ์€์ด๋ž€,

ํด๋ผ์ด์–ธํŠธ HTTP์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ , ๋™์  ์›น ์ฝ˜ํ…์ธ ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :   MVC ํŒจํ„ด์—์„œ ์„œ๋ธ”๋ฆฟ์„ Controller๋กœ ์ด์šฉํ•˜๊ธฐ๋„ํ•œ๋‹ค.

์„œ๋ธ”๋ฆฟ์€ ์ž๋ฐ” ํ‘œ์ค€์—์„œ ์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๊ณ ,

์ปจํŠธ๋กค๋Ÿฌ (์ฃผ๋กœ MVC ์ผ๋ถ€๋ถ„์œผ๋กœ ์‚ฌ์šฉ) ๋Š” ์„œ๋ธ”๋ฆฟ์„ ์ข€ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.

 

์ฆ‰,  ์ปจํŠธ๋กค๋Ÿฌ๋„ ์„œ๋ธ”๋ฆฟ๊ณผ ๊ฐ™์ด ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :   ๊ทธ๋ฆฌ๊ณ  ์„œ๋ธ”๋ฆฟ์€ ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด์„œ

URL-Mapping ์„ ์ง„ํ–‰ํ•ด์ค˜์•ผํ•˜๋Š”๋ฐ

์ด๋•Œ,  @WebServlet("/HelloWorld") ์–ด๋…ธํ…Œ์ด์…˜์„ ์ด์šฉํ•œ๋‹ค.

( web.xml ํŒŒ์ผ์„ ์ˆ˜์ •ํ•  ํ•„์š” ์—†์ด ์„œ๋ธ”๋ฆฟ ํด๋ž˜์Šค๋ฅผ ์ง์ ‘ URL ํŒจํ„ด์— ๋งคํ•‘ )

 

 

๐Ÿ‘จ‍๐Ÿ’ผ : ์„œ๋ธ”๋ฆฟ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ !

 

[JSP] Java Servlet

[์„œ๋ธ”๋ฆฟ servlet] ์ž๋ฐ” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ๋•Œ ์„œ๋ฒ„์ธก์—์„œ ์‹คํ–‰๋˜๋Š” ์ž๋ฐ” ํ”„๋กœ๊ทธ๋žจ์„ ๋œปํ•œ๋‹ค. ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ , ๋™์  ์›น ์ฝ˜ํ…์ธ ๋ฅผ ์ƒ

hyejux.tistory.com

 

 

๐Ÿ‘จ‍๐Ÿ’ผ : @webServlet("*.???") ์€

์™€์ผ๋“œ์นด๋“œ ํŒจํ„ด์œผ๋กœ .main์œผ๋กœ ๋๋‚˜๋Š” ๋ชจ๋“  URL ์š”์ฒญ์„ ํ•ด๋‹น ์„œ๋ธ”๋ฆฟ(์ปจํŠธ๋กค๋Ÿฌ)๊ฐ€ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•œ๋‹ค.

์ฆ‰, *.main ์œผ๋กœ ๋๋‚˜๋Š” ์š”์ฒญ๋“ค์€ ์ „๋ถ€ mainController ๋กœ ๋ชจ์ธ๋‹ค.

@WebServlet("*.main")
public class mainController extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doAction(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doAction(request, response);
	}
	
	protected void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :  ์—ฌ๊ธฐ์„œ request ๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์š”์ฒญํ•œ ์ •๋ณด,

response ๋Š” ์„œ๋ฒ„๊ฐ€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์‘๋‹ตํ• ๋•Œ ์ •๋ณด๋“ค์„ ๋‹ด๊ณ  ์žˆ๋‹ค.

(๋‚ด์žฅ๊ฐ์ฒด ์ž…๋‹ˆ๋‹ค. was ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•ด์ฃผ๋Š” ๊ฐ์ฒด)

์ž์„ธํ•œ ๋ฉ”์„œ๋“œ๋Š” ์•„๋ž˜์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.

https://hyejux.tistory.com/686

 

[JSP] JSP : Java Server Pages (๊ฐœ๋…)

[ JSP ๋ž€? ] JavaServer Pages ์˜ ์ค„์ž„๋ง๋กœ ๋™์ ์ธ ์›น ํŽ˜์ด์ง€๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๊ธฐ์ˆ ์ด๋‹ค. ์ž๋ฐ”๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋ฉฐ, HTML ์ฝ”๋“œ์— java ์ฝ”๋“œ๋ฅผ ์‚ฝ์ž…ํ•˜์—ฌ ๋™์  ์ฝ˜ํ…์ธ ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. [

hyejux.tistory.com

 

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :   ์š”์ฒญ๋œ URI , PATH ๊ฐ’์„ ์–ป์–ด๋‚ด command ์— ๋„ฃ๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์š”์ฒญ์„ ๋ถ„๊ธฐํ•ด์ค€๋‹ค.

(command ์ •๋ณด์— ๋งž๊ฒŒ ์š”์ฒญ์„ ๋ณด๋‚ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.)

command ์™€ ๊ฐ™์€ ์ •๋ณด๋ฅผ ์ฐพ์•„ service์— ๋ณด๋‚ธ๋‹ค.

 

String uri = request.getRequestURI();
String path = request.getContextPath();
String command = uri.substring(path.length());

//String getRequestURI() : ์›น ์„œ๋ฒ„๋กœ ์š”์ฒญ ์‹œ, ์š”์ฒญ์— ์‚ฌ์šฉ๋œ URL ๋กœ๋ถ€ํ„ฐ URI ๊ฐ’์„ ๋ฆฌํ„ดํ•œ๋‹ค. 
//String getContextPath() : ํ•ด๋‹น JSP ํŽ˜์ด์ง€๊ฐ€ ์†ํ•œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ฝ˜ํ…์ŠคํŠธ ๊ฒฝ๋กœ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

 

if(command.equals("/main/home.main")) {
		service = new MypageServiceImpl();
		service.checkCheckin(request, response);
} else if(command.equals("/main/dohome.main")) {
		service = new MypageServiceImpl();
		service.doCheckin(request, response);
}

 


Service ๋ ˆ์ด์–ด

 

๐Ÿ‘จ‍๐Ÿ’ผ : Service ๋ ˆ์ด์–ด ๋Š” ์ปจํŠธ๋กค๋Ÿฌ์˜ ์š”์ฒญ์„ ๋ฐ›์•„์„œ ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•œ๋‹ค.

 

 

๐Ÿ‘จ‍๐Ÿ’ผ : Service , ServiceImpl  ๋Š” 

Service ๋Š” ์ฃผ๋กœ interface ๋กœ ๋งŒ๋“ค๊ณ 

ServiceImpl ์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•ด์ค€๋‹ค. 

public interface Boardservice {

	 void regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
	 void getList (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
	
}
@Override
	public void regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String writer = request.getParameter("writer");
		String title  = request.getParameter("title");
		String content = request.getParameter("content");
		BoardDAO dao = BoardDAO.getInstance();
		System.out.println("impl");
		dao.regist(writer, title, content);
		// ๋ชฉ๋ก ์ด๋™  -- ํ‹€๋ฆผ
		request.getRequestDispatcher("board_list.jsp").forward(request, response);
		// ๋ชฉ๋ก ํ™”๋ฉด redirect ๋กœ ํƒœ์›Œ์„œ ๋‚˜๊ฐ 
		//response.sendRedirect("list.board");

	}

	@Override
	public void getList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		BoardDAO dao = BoardDAO.getInstance();
		ArrayList<BoardDTO> list = dao.getList();
		//requset ์— ์ €์žฅ ํฌ์›Œ๋“œ๋กœ ๋‚˜๊ฐ
		request.setAttribute("list", list);  //board_list 
		request.getRequestDispatcher("board_list.jsp").forward(request, response);

		
	}

 

 

 


 

JDBC, DAO , DTO  (+ Mapper (Mybatis) )

 

๐Ÿ‘จ‍๐Ÿ’ผ :  ์ด์ œ DB ์™€ ์—ฐ๋™๋˜์–ด ๋ฐ์ดํ„ฐ ์ด๋™์„ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ๋Š” JDBC๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

 

๐Ÿ‘จ‍๐Ÿ’ผ :  JDBC (Java Database Connectivity) Java์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” Java API

DB์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์‰ฝ๊ฒŒ ๊ฐ€์ ธ์˜ค๊ณ  ๋นผ๋‚ด๊ธฐ ์œ„ํ•ด DTO์™€ DAO๋ฅผ ์“ด๋‹ค.

JDBC ๋Š” row level๋ถ€ํ„ฐ ORM( ๊ฐ์ฒด์™€ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋งคํ•‘ํ•˜๋Š” ๊ฒƒ)์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ๋‹ค.

 

DTO ( Data Transfer Object ) ๋Š” DB์—์„œ ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฐ์ฒด 

๋”๋ณด๊ธฐ

DTO ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ์ƒ์„ฑ์ž๋“ค์ด ๋ชจ์—ฌ์žˆ๋‹ค.

public class BoardDTO {

	private int bno;
	private String writer;
	private String title;
	private String content;
	private Timestamp regdate;
	private int hit;
	
	public BoardDTO() {
	
	}
	
	public BoardDTO(int bno, String writer, String title, String content, Timestamp regdate, int hit) {
		super();
		this.bno = bno;
		this.writer = writer;
		this.title = title;
		this.content = content;
		this.regdate = regdate;
		this.hit = hit;
	}

 

DAO ( Data Access Object ) ๋Š” DB์— ์ ‘๊ทผํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌ (CRUD ๋“ฑ)๋ฅผ ์œ„ํ•œ ๊ฐ์ฒด

๋”๋ณด๊ธฐ

DAO

public class UserDAO {
   
   //DAO๋Š” ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์—ฌ๋Ÿฌ ๊ฐœ ๋งŒ๋“ค ํ•„์š”๊ฐ€ ์—†์œผ๋ฏ€๋กœ 
   //๊ฐ์ฒด๊ฐ€ 1๊ฐœ๋งŒ ์ƒ์„ฑ๋˜๋„๋ก singletonํ˜•์‹์œผ๋กœ ์„ค๊ณ„
   
   //1. ๋‚˜ ์ž์‹ ์˜ ๊ฐ์ฒด๋ฅผ 1๊ฐœ๋งŒ ์ƒ์„ฑํ•˜๊ณ , private์„ ๋ถ™์ž„
   private static UserDAO instance = new UserDAO();
   
   //2. ์ง์ ‘ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์—†๋„๋ก ์ƒ์„ฑ์ž์—๋„ private๋ฅผ ๋ถ™์ž„
   private UserDAO(){
      
      //์ปค๋„ฅ์…˜ํ’€์— ์‚ฌ์šฉํ•  ๊ฐ์ฒด๋ฅผ ์–ป์–ด ์˜ด
      try {
         InitialContext init = new InitialContext();//์‹œ์ž‘์„ค์ •๊ฐ์ฒด
         
         ds = (DataSource)init.lookup("java:comp/env/jdbc/oracle");
         
      } catch (Exception e) {
         System.out.println("์ปค๋„ฅ์…˜ ํ’€ ์—๋Ÿฌ");
      }
      
   }
   //3. ๊ฐ์ฒด ์ƒ์„ฑ์„ ์š”๊ตฌํ•  ๋•Œ getter๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ 1๋ฒˆ์˜ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜
   public static UserDAO getInstance() {
      return instance;
   }
         
   //์ปค๋„ฅ์…˜ ํ’€ ๊ฐ์ฒด์ •๋ณด
   private DataSource ds;
   
   
   public int findUser(String id) {
	   int result = 0;
	   String sql = "SELECT COUNT(*) FROM USERS WHERE ID = ?";
	   
	   Connection conn = null;
	   PreparedStatement pstmt = null;
	   ResultSet rs = null;
	   
	   try {
		   conn = ds.getConnection();
		   pstmt = conn.prepareStatement(sql);
		   pstmt.setString(1, id);
		   
		   rs = pstmt.executeQuery();
		   
		   
		   if(rs.next()) { // ์œ ์ €๊ฐ€ ์žˆ๋‹ค๋Š” ๋œป
			   result = rs.getInt(1);
		   }
		    
	   }catch (Exception e ) {
		  e.printStackTrace();
		  
	   }finally {
		   JdbcUtil.close(conn, pstmt, null);
	   }
 	  
	   return result;
   }
   
   
   public void insertUser(String id, String pw, String name, String email, String gender) {
	   
	   String sql = "INSERT INTO USERS(ID, PW, NAME, EAMIL, GENDER) VALUES(?,?,?,?,?)";
	   
	   Connection conn = null;
	   PreparedStatement pstmt = null;
	   
	   
	   try {
		   conn = ds.getConnection();
		   pstmt = conn.prepareStatement(sql);
		   
		   pstmt.setString(1, id);
		   pstmt.setString(2, pw);
		   pstmt.setString(3, name);
		   pstmt.setString(4, email);
		   pstmt.setString(5, gender);
		   
		   pstmt.executeUpdate(); //์‹คํ–‰
		   
		   
	   }catch (Exception e) {
		   e.printStackTrace();
		   
	   }finally {
		   JdbcUtil.close(conn, pstmt, null);
	   }
	   
   }

 

JDBC ์ž์„ธํ•œ ์ •๋ณด๋Š” ์—ฌ๊ธฐ๋กœ

 

[JSP] JDBC (Java Database Connectivity)

[ JDBC ๋ž€? ] Java Database Connectivity์˜ ์•ฝ์ž๋กœ ์ž๋ฐ” ํ”„๋กœ๊ทธ๋žจ์—์„œ SQL๋ฌธ์„ ์‹คํ–‰ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ JAVA API [ ์—ฐ๊ฒฐ API connector ] MYSQL , ORACLE ์— ๋”ฐ๋ผ ์ „์šฉ JDBC ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. [ SQL

hyejux.tistory.com

 

 

๐Ÿ‘จ‍๐Ÿ’ผ : ํ•˜์ง€๋งŒ JDBC ์˜ ๋‹จ์ ์€  ๋งŽ์€ ์ฝ”๋“œ ์ค‘๋ณต์ด ์ƒ๊ธด๋‹ค. ใ…œใ…œ

์ด๋•Œ ์ฝ”๋“œ ์ค‘๋ณต์„ ์ค„์—ฌ์ฃผ๋Š” Mapper ๊ฐ€ ์žˆ๋‹ค.

  • SQL ๋ฌธ๊ณผ ๊ฐ์ฒด(Object)์˜ ํ•„๋“œ๋ฅผ ๋งคํ•‘ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ์ฒดํ™”
  • ์ฟผ๋ฆฌ ์ˆ˜ํ–‰ ๊ฒฐ๊ณผ์™€ ๊ฐ์ฒด์˜ ํ•„๋“œ๋ฅผ ๋งตํ•‘ & RowMapper ์žฌํ™œ์šฉ
  • JdbcTemplate๊ฐ€ JDBC์—์„œ ๋ฐ˜๋ณต์ ์œผ๋กœ ํ•ด์•ผ ํ•˜๋Š” ๋งŽ์€ ์ž‘์—…๋“ค์„ ๋Œ€์‹ ํ•ด์คŒ

 

๐Ÿ‘จ‍๐Ÿ’ผ :   ๋Œ€ํ‘œ์ ์œผ๋กœ Mybatis ๊ฐ€ ๊ทธ์— ํ•ด๋‹นํ•œ๋‹ค.

์—ฌ๊ธฐ์„œ Mybatis ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด DAO๊ณ„์ธต์„ ๋Œ€์‹ ํ•˜๊ฒŒ๋˜๊ณ ,

interface ๊ตฌํ˜„์ด ์•„๋‹Œ xmlํŒŒ์ผ๋กœ ๊ตฌํ˜„์„ ๋Œ€์ฒดํ•˜๊ฒŒ๋œ๋‹ค.

 

 

1) mapper interface ์ƒ์„ฑ

Mybatis๊ฐ€ Dao์˜ ์‹ค์ œ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค ๋•Œ, ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž‘์„ฑํ•œ Mybatis MapperํŒŒ์ผ(.xml)์„ ์ฐธ๊ณ ํ•ด ๋งŒ๋“ญ๋‹ˆ๋‹ค.

 

public interface FreeBoard {

	public String now();
	//...์ƒ๋žต
}

 

 

2) mapper๊ตฌํ˜„์ฒด ์ƒ์„ฑ

 

<?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="FreeBoard์˜ ํ’€๋„ค์ž„(ํŒจํ‚ค์ง€ํฌํ•จ๋ช…)">
	
    <select id="๋ฉ”์†Œ๋“œ๋ช…" resultType="returnํƒ€์ž… ํ’€ ๋„ค์ž„" parameterType="ํŒŒ๋ผ๋ฏธํ„ฐํƒ€์ž… ํ’€๋„ค์ž„">
     ์›ํ•˜๋Š” ์ฟผ๋ฆฌ๋ฌธ (;์ œ์™ธํ•˜๊ธฐ)
    </select>

</mapper>

 

 

๋งˆ์ด๋ฐ”ํ‹ฐ์Šค์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋Š” ์—ฌ๊ธฐ๋กœ !

 

๐Ÿ’ข[JSP] JDBC vs Mybatis (๋งˆ์ด๋ฐ”ํ‹ฐ์Šค)

JDBC์˜ ๋ถˆํŽธํ•จ…JDBC๋Š” ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ row level๋ถ€ํ„ฐ ORM์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์„ ๊ฐ€์ง„๋‹ค.ํ•˜์ง€๋งŒ, ๋„ˆ๋ฌด ๋งŽ์€ ์ฝ”๋“œ๊ฐ€ ๋ฐ˜๋ณต๋˜๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.Persistence Framework๋ž€?์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐ์ดํ„ฐ์™€ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ(์˜ˆ

hyejux.tistory.com

 


forward , redirect 

 

๐Ÿ‘จ‍๐Ÿ’ผ : JSP ์—์„œ ํŠน์ • ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

forward ์™€ redirect ์ด๋‹ค.

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :  forward  :

request ๊ฐ’, response ๊ฐ€ ์œ ์ง€๋œ๋‹ค.

์ด๋™๋œ url ํ™”๋ฉด์ด ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค.

//์ž๋ฐ”์—์„œ forward ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
RequestDispatcher dp = request.getRequestDispatcher("/actionTag/forward_ex04.jsp");//์ด๋™ํ•  url ์ฃผ์†Œ
dp.forward(request, response);

 

 

๐Ÿ‘จ‍๐Ÿ’ผ :  redirect

request ๊ฐ’, response ๊ฐ€ ์œ ์ง€๋˜์ง€์•Š๋Š”๋‹ค (์ƒˆ๋กœ ๋งŒ๋“ค์–ด์ง)

์ด๋™๋œ url ํ™”๋ฉด์— ๋ณด์ธ๋‹ค.

 response.sendRedirect("sendd_ex03.jsp");

 

 

	/* 
	ํ…Œ์ด๋ธ” ๋ณ„ DTO ์ƒ์„ฑ 
	controller ๊ตฌํ˜„
	service ๊ตฌํ˜„
	mapper ๊ตฌํ˜„ (data)
	database ํ™•์ธ
	*/