{"id":438,"date":"2017-08-02T15:36:44","date_gmt":"2017-08-02T15:36:44","guid":{"rendered":"http:\/\/happily70.dothome.co.kr\/?p=438"},"modified":"2017-08-02T15:36:44","modified_gmt":"2017-08-02T15:36:44","slug":"dto-%ec%99%80-dao","status":"publish","type":"post","link":"http:\/\/happily70.dothome.co.kr\/?p=438","title":{"rendered":"DTO \uc640 DAO"},"content":{"rendered":"<p><strong>DAO(Data Access Object)<\/strong>\ub294 DB\ub97c \uc0ac\uc6a9\ud574 \ub370\uc774\ud130\ub97c \uc870\ud654\ud558\uac70\ub098 \uc870\uc791\ud558\ub294 \uae30\ub2a5\uc744<br \/>\n\uc804\ub2f4\ud558\ub3c4\ub85d \ub9cc\ub4e0 \uc624\ube0c\uc81d\ud2b8\ub97c \ub9d0\ud55c\ub2e4.<\/p>\n<p> \uc0ac\uc6a9\uc790\ub294 \uc790\uc2e0\uc774 \ud544\uc694\ud55c Interface\ub97c DAO\uc5d0\uac8c \ub358\uc9c0\uace0 DAO\ub294 \uc774 \uc778\ud130\ud398\uc774\uc2a4\ub97c<br \/>\n\uad6c\ud604\ud55c \uac1d\uccb4\ub97c \uc0ac\uc6a9\uc790\uc5d0\uac8c \ud3b8\ub9ac\ud558\uac8c \uc0ac\uc6a9 \ud560 \uc218 \uc788\ub3c4\ub85d \ubc18\ud658\ud574\uc90d\ub2c8\ub2e4.<\/p>\n<p> DB\uc5d0 \ub300\ud55c \uc811\uadfc\uc744 DAO\uac00 \ub2f4\ub2f9\ud558\ub3c4\ub85d \ud558\uc5ec \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc5d1\uc138\uc2a4\ub97c DAO\uc5d0\uc11c\ub9cc<br \/>\n\ud558\uac8c \ub418\uba74 \ub2e4\uc218\uc758 \uc6d0\uaca9\ud638\ucd9c\uc744 \ud1b5\ud55c \uc624\ubc84\ud5e4\ub4dc\ub97c VO\ub098 DTO\ub97c \ud1b5\ud574 \uc904\uc77c \uc218 \uc788\uace0<br \/>\n\ub2e4\uc218\uc758 DB \ud638\ucd9c\ubb38\uc81c\ub97c \ud574\uacb0\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub610\ud55c \ub2e8\uc21c\ud788 \uc77d\uae30\ub9cc \ud558\ub294 \uc5f0\uc0b0\uc774\ubbc0\ub85c<br \/>\n\ud2b8\ub79c\uc7ad\uc158 \uac04\uc758 \uc624\ubc84\ud5e4\ub4dc\ub97c \uac10\uc18c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p><strong>DTO(Data Transfer Object)<\/strong>\ub294 VO(Value Object)\ub85c \ubc14\uafd4 \ub9d0\ud560 \uc218 \uc788\ub294\ub370<br \/>\n\uacc4\uce35\uac04 \ub370\uc774\ud130 \uad50\ud658\uc744 \uc704\ud55c \uc790\ubc14\ube48\uc988\ub97c \ub9d0\ud55c\ub2e4. \uc5ec\uae30\uc11c \ub9d0\ud558\ub294 \uacc4\uce35\uac04\uc758<br \/>\n\ucee8\ud2b8\ub864\ub7ec, \ubdf0, \ube44\uc988\ub2c8\uc2a4 \uacc4\uce35, \ud37c\uc2dc\uc2a4\ud134\uc2a4 \uacc4\uce35\uc744 \ub9d0\ud558\uba70 \uac01 \uacc4\uce35\uac04 \ub370\uc774\ud130 \uad50\ud658\uc744<br \/>\n\uc704\ud55c \uac1d\uccb4\ub97c DTO \ub610\ub294 VO\ub77c\uace0 \ubd80\ub978\ub2e4.<\/p>\n<p>\ub300\ud45c\uc801\uc778 DTO\ub85c\ub294 \ud3fc\ub370\uc774\ud130\ube48, \ub370\uc774\ud130\ubca0\uc774\uc2a4 \ud14c\uc774\ube14\ube48 \ub4f1\uc774 \uc788\uc73c\uba70, \uac01 \ud3fc\uc694\uc18c\ub098,<br \/>\n\ub370\uc774\ud130\ubca0\uc774\uc2a4 \ub808\ucf54\ub4dc\uc758 \ub370\uc774\ud130\ub97c \ub9e4\ud551\ud558\uae30 \uc704\ud55c \ub370\uc774\ud130 \uac1d\uccb4\ub97c \ub9d0\ud55c\ub2e4. \uc989 \ud3fc \ud544\ub4dc\ub4e4\uc758<br \/>\n\uc774\ub984\uc744 \uadf8\ub300\ub85c \uac00\uc9c0\uace0 \uc788\ub294 \uc790\ubc14\ube48 \uac1d\uccb4\ub97c \ud3fc \ud544\ub4dc\uc640 \uadf8\ub300\ub85c \ub9e4\ud551\ud558\uc5ec \ube44\uc988\ub2c8\uc2a4 \uacc4\uce35\uc73c\ub85c<br \/>\n\ubcf4\ub0bc \ub54c \uc0ac\uc6a9\ud558\ub098\ub2e4. \uc774\ub7f0 \uac1d\uccb4\ub97c DTO\ub77c\uace0 \ubd80\ub974\uba70 VO(Value Object) \ud328\ud134\uc774\ub77c\uace0\ub3c4 \ud55c\ub2e4.<br \/>\nVO \ud328\ud134\uc740 \ub370\uc774\ud130 \uc804\ub2ec\uc744 \uc704\ud55c \uac00\uc7a5 \ud6a8\uc728\uc801\uc778 \ubc29\ubc95\uc774\uc9c0\ub9cc, \ud074\ub798\uc2a4 \uc120\uc5b8\uc744 \uc704\ud574 \ub9ce\uc740<br \/>\n\ucf54\ub4dc\uac00 \ud544\uc694\ud558\ub2e4\ub294 \ub2e8\uc810\uc774 \uc788\ub2e4.<\/p>\n<p>\uc77c\ubc18\uc801\uc778 DTO\ub294 \ub85c\uc9c1\uc744 \uac16\uace0 \uc788\uc9c0 \uc54a\ub2e4. \uc21c\uc218\ud55c \ub370\uc774\ud130 \uac1d\uccb4\uc774\uba70 \uc18d\uc0c1\uacfc \uadf8 \uc18d\uc131\uc5d0<br \/>\n\uc811\uadfc\ud558\uae30 \uc704\ud55c getter, setter \uba54\uc18c\ub4dc\ub9cc \uac00\uc9c4 \ud074\ub798\uc2a4\ub97c \ub9d0\ud55c\ub2e4. \uc5ec\uae30\uc5d0 \ucd94\uac00\uc801\uc73c\ub85c<br \/>\ntoString(), equals(), \ub4f1\uc758 Object \ud074\ub798\uc2a4 \uba54\uc18c\ub4dc\ub97c \uc791\uc131\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p>\uc989, \uacc4\uce35 \uac04\uc758 \ub370\uc774\ud130 \uc804\ub2ec\uc5d0 \uc0ac\uc6a9\ud558\ub294 \ub370\uc774\ud130 \uac1d\uccb4\ub4e4\uc744 \ub9d0\ud55c\ub2e4.<\/p>\n<p>1. DTO \ud074\ub798\uc2a4 \uc608\uc81c<\/p>\n<p>public class DTOBean {<\/p>\n<p> private String name;<\/p>\n<p> private int value;<\/p>\n<p> private String data;<\/p>\n<p> public String getName() {<br \/>\n  return name;<br \/>\n }<\/p>\n<p> public void setName(String name) {<br \/>\n  this.name = name;<br \/>\n }<\/p>\n<p> public int getValue() {<br \/>\n  return value;<br \/>\n }<\/p>\n<p> public void setValue(int value) {<br \/>\n  this.value = value;<br \/>\n }<\/p>\n<p> public String getData() {<br \/>\n  return data;<br \/>\n }<\/p>\n<p> public void setData(String data) {<br \/>\n  this.data = data;<br \/>\n }<br \/>\n}<\/p>\n<p>2. DAO \ud074\ub798\uc2a4 \uc608\uc81c<\/p>\n<p>\/\/DB\uc640 \uc5f0\uacb0\ud560 Connection\uc744 \uac00\uc838\uc628\ub2e4.<br \/>\n\/\/\uc5b4\ub5a4 DB\ub97c \uc0ac\uc6a9\ud560 \uac83\uc774\uba70, \uc5b4\ub5a4 \ub4dc\ub77c\uc774\ube0c\uc640 \ub85c\uadf8\uc778 \uc815\ubcf4\ub97c \uc0ac\uc6a9\ud560 \uac83\uc778\uac00.<br \/>\n\/\/\uc791\uc5c5\uc774 \ub05d\ub098\uba74 \uc0ac\uc6a9\ud55c \ub9ac\uc18c\uc2a4\ub97c \uc2dc\uc2a4\ud15c\uc5d0 \ub3cc\ub824\uc900\ub2e4.<br \/>\npublic class TestDao {<\/p>\n<p> public void add(DTOBean dto) throws ClassNotFoundException, SQLException{<br \/>\n  Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);<\/p>\n<p>  Connection c= DriverManager.getConnection(&#8220;jdbc:mysql:\/\/localhost\/springbook&#8221;, &#8220;spring&#8221;, &#8220;book&#8221;);<\/p>\n<p>  PreparedStatement ps = c.prepareStatement(&#8220;insert into users(id,name,password) value(?,?,?)&#8221;);<\/p>\n<p>  ps.setString(1,  dto.getName());<br \/>\n  ps.setInt(2,  dto.getValue());<br \/>\n  ps.setString(3,  dto.getData());<\/p>\n<p>  ps.executeUpdate();<\/p>\n<p>  ps.close();<br \/>\n  c.close();<br \/>\n }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DAO(Data Access Object)\ub294 DB\ub97c \uc0ac\uc6a9\ud574 \ub370\uc774\ud130\ub97c \uc870\ud654\ud558\uac70\ub098 \uc870\uc791\ud558\ub294 \uae30\ub2a5\uc744 \uc804\ub2f4\ud558\ub3c4\ub85d \ub9cc\ub4e0 \uc624\ube0c\uc81d\ud2b8\ub97c \ub9d0\ud55c\ub2e4. \uc0ac\uc6a9\uc790\ub294 \uc790\uc2e0\uc774 \ud544\uc694\ud55c Interface\ub97c DAO\uc5d0\uac8c \ub358\uc9c0\uace0 DAO\ub294 \uc774 \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud55c \uac1d\uccb4\ub97c \uc0ac\uc6a9\uc790\uc5d0\uac8c \ud3b8\ub9ac\ud558\uac8c \uc0ac\uc6a9 \ud560 \uc218 \uc788\ub3c4\ub85d \ubc18\ud658\ud574\uc90d\ub2c8\ub2e4. DB\uc5d0 \ub300\ud55c \uc811\uadfc\uc744 DAO\uac00 \ub2f4\ub2f9\ud558\ub3c4\ub85d \ud558\uc5ec \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc5d1\uc138\uc2a4\ub97c DAO\uc5d0\uc11c\ub9cc \ud558\uac8c \ub418\uba74 \ub2e4\uc218\uc758 \uc6d0\uaca9\ud638\ucd9c\uc744 \ud1b5\ud55c \uc624\ubc84\ud5e4\ub4dc\ub97c VO\ub098 DTO\ub97c \ud1b5\ud574 \uc904\uc77c \uc218 \uc788\uace0 \ub2e4\uc218\uc758 DB \ud638\ucd9c\ubb38\uc81c\ub97c<\/p>\n<footer class=\"entry-footer index-entry\">\n<div class=\"post-social pull-left\"><a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D438\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-facebook\" aria-hidden=\"true\"><\/i><\/a><a href=\"https:\/\/twitter.com\/home?status=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D438\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-twitter\" aria-hidden=\"true\"><\/i><\/a><a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D438&#038;title=DTO+%EC%99%80+DAO\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-linkedin\" aria-hidden=\"true\"><\/i><\/a><\/div>\n<p class=\"link-more\"><a href=\"http:\/\/happily70.dothome.co.kr\/?p=438\" class=\"more-link\">Continue reading <span class=\"meta-nav\">\u2192<\/span><\/a><\/p>\n<\/footer>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,33,11],"tags":[],"class_list":["post-438","post","type-post","status-publish","format-standard","hentry","category-back-end","category-developement","category-spring"],"_links":{"self":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/438"}],"collection":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=438"}],"version-history":[{"count":1,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":439,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/438\/revisions\/439"}],"wp:attachment":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}