{"id":2239,"date":"2021-07-17T13:17:00","date_gmt":"2021-07-17T04:17:00","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2239"},"modified":"2021-07-17T14:22:35","modified_gmt":"2021-07-17T05:22:35","slug":"mysql-%ec%9d%84-%ec%9d%b4%ec%9a%a9%ed%95%9c-%eb%8d%b0%ec%9d%b4%ed%83%80-%ec%97%91%ec%84%b8%ec%8a%a4","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2239","title":{"rendered":"MySQL \uc744 \uc774\uc6a9\ud55c \ub370\uc774\ud0c0 \uc5d1\uc138\uc2a4"},"content":{"rendered":"<h1>MySQL \uc744 \uc774\uc6a9\ud55c \ub370\uc774\ud0c0 \uc5d1\uc138\uc2a4<\/h1>\n<h2>\ubaa9\ud45c<\/h2>\n<p>MySQL \ub370\uc774\ud0c0\ubca0\uc774\uc2a4\ub97c \uc774\uc6a9\ud574, \ub370\uc774\ud0c0\ub97c insert\/update\/select \ub97c \uc218\ud589\ud569\ub2c8\ub2e4.<\/p>\n<h2>\ud504\ub85c\uc81d\ud2b8 \uc0dd\uc131<\/h2>\n<p>\uc2e0\uaddc \ud504\ub85c\uc81d\ud2b8\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<p>\uc758\uc874\uc131\uc740 DevTools, Lombok, Spring Web, Thymeleaf, Spring Data JPA, MySQL \uc744 \uc120\ud0dd\ud569\ub2c8\ub2e4.<\/p>\n<h2>\ud30c\uc77c \ucd94\uac00<\/h2>\n<h3>Entity \uc0dd\uc131<\/h3>\n<p>User.java \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Entity\npublic class User {\n    @Id\n    @GeneratedValue(strategy= GenerationType.IDENTITY)\n    private Integer id;\n\n    private String name;\n\n    private String email;\n\n    public Integer getId() {\n        return id;\n    }\n\n    public void setId(Integer id) {\n        this.id = id;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public String getEmail() {\n        return email;\n    }\n\n    public void setEmail(String email) {\n        this.email = email;\n    }\n}<\/code><\/pre>\n<h3>Repository \uc0dd\uc131<\/h3>\n<p>UserRepository.java \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">public interface UserRepository extends CrudRepository&lt;User, Integer&gt; {\n\n}<\/code><\/pre>\n<h3>Controller \uc0dd\uc131<\/h3>\n<p>MainController.java \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Controller \/\/ \ucee8\ud2b8\ub864\ub7ec\uc784\uc744 \uba85\uc2dc\ud569\ub2c8\ub2e4.\n@RequestMapping(path=&quot;\/demo&quot;) \/\/ URL \uc911 \/demo \ub85c \uc2dc\uc791\ud558\ub294 URL \uc744 \ub9e4\ud551\ud569\ub2c8\ub2e4.\npublic class MainController {\n\n    @Autowired \/\/ \uc544\ub798 \ud074\ub798\uc2a4\uac00 \uc2a4\ud504\ub9c1\uc5d0 \uc758\ud574 \uc790\ub3d9\uc0dd\uc131\ub428\uc744 \ud45c\uc2dc\ud569\ub2c8\ub2e4.\n    private UserRepository userRepository;\n\n    @PostMapping(path=&quot;\/add&quot;) \/\/ POST \uc694\uccad\uc5d0\ub9cc \ub300\uc751\ud569\ub2c8\ub2e4.\n    public @ResponseBody\n    String addNewUser (@RequestParam String name\n            , @RequestParam String email) {\n\n        \/\/ @ResponseBody \ub294 \ub9ac\ud134\uac12\uc774 \ube0c\ub77c\uc6b0\uc800\uc5d0 \uc804\uc1a1\ub418\ub294 \ub370\uc774\ud0c0\uc784\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4.\n        \/\/ (\ud15c\ud50c\ub9bf \ud30c\uc77c\uc744 \ucc3e\uc9c0 \uc54a\uace0 \uadf8\ub300\ub85c \ub9ac\ud134\uac12\uc744 \ube0c\ub77c\uc6b0\uc800\uc5d0 \uc804\uc1a1\ud569\ub2c8\ub2e4.)\n\n        \/\/ @RequestParam \ub97c \uc9c0\uc815\ud574\uc11c URL \ud30c\ub77c\ubbf8\ud130\uac00 \uac01\uac01\uc758 \ubcc0\uc218\uc5d0 \uc790\ub3d9 \ud560\ub2f9\ub429\ub2c8\ub2e4.\n\n        User n = new User();\n        n.setName(name);\n        n.setEmail(email);\n        userRepository.save(n);\n        return &quot;Saved&quot;;\n    }\n\n    @GetMapping(path=&quot;\/all&quot;)\n    public @ResponseBody Iterable&lt;User&gt; getAllUsers() {\n\n        return userRepository.findAll();\n    }\n}<\/code><\/pre>\n<h2>MySQL \uc124\uc815<\/h2>\n<pre><code class=\"language-sql\">create database db_example;\n\nuse db_example;\n\nCREATE TABLE `user` (\n    `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n    `email` VARCHAR(255) NULL DEFAULT NULL COLLATE &#039;utf8_general_ci&#039;,\n    `name` VARCHAR(255) NULL DEFAULT NULL COLLATE &#039;utf8_general_ci&#039;\n)\nCOLLATE=&#039;utf8_general_ci&#039;\nENGINE=INNODB;<\/code><\/pre>\n<h2>application.properties \uc124\uc815<\/h2>\n<pre><code class=\"language-properties\"># spring.jpa.hibernate.ddl-auto=update\nspring.datasource.url=jdbc:mysql:\/\/${MYSQL_HOST:localhost}:3306\/db_example\nspring.datasource.username=springuser\nspring.datasource.password=ThePassword\nspring.datasource.driver-class-name =com.mysql.jdbc.Driver\n#spring.jpa.show-sql: true<\/code><\/pre>\n<h2>\ud504\ub85c\uc81d\ud2b8 \uc2e4\ud589<\/h2>\n<p>\ud504\ub85c\uc81d\ud2b8\ub97c \uc2e4\ud589 \ud6c4 \uc544\ub798 \uba85\ub839\uc744 \uc785\ub825\ud574\uc11c \ub370\uc774\ud0c0\ub97c \uc785\ub825\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">curl localhost:8080\/demo\/add -d name=First -d email=someemail@someemailprovider.com<\/code><\/pre>\n<p>\uc544\ub798 \ub9c1\ud06c\ub97c \uc5f4\uc5b4 \ub370\uc774\ud0c0\uac00 \uc785\ub825\ub418\uc5c8\ub294\uc9c0 \ud655\uc778\ud569\ub2c8\ub2e4.<\/p>\n<p><a href=\"http:\/\/localhost:8080\/demo\/all\">http:\/\/localhost:8080\/demo\/all<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \uc744 \uc774\uc6a9\ud55c \ub370\uc774\ud0c0 \uc5d1\uc138\uc2a4 \ubaa9\ud45c MySQL \ub370\uc774\ud0c0\ubca0\uc774\uc2a4\ub97c \uc774\uc6a9\ud574, \ub370\uc774\ud0c0\ub97c insert\/update\/select \ub97c \uc218\ud589\ud569\ub2c8\ub2e4. \ud504\ub85c\uc81d\ud2b8 \uc0dd\uc131 \uc2e0\uaddc \ud504\ub85c\uc81d\ud2b8\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. \uc758\uc874\uc131\uc740 DevTools, Lombok, Spring Web, Thymeleaf, Spring Data JPA, MySQL \uc744 \uc120\ud0dd\ud569\ub2c8\ub2e4. \ud30c\uc77c \ucd94\uac00 Entity \uc0dd\uc131 User.java \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. @Entity public class User { @Id @GeneratedValue(strategy= GenerationType.IDENTITY) private Integer id; private String name; private String email; public\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2239\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-2239","post","type-post","status-publish","format-standard","hentry","category-spring-boot-2-5"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2239"}],"version-history":[{"count":5,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2239\/revisions"}],"predecessor-version":[{"id":2245,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2239\/revisions\/2245"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}