Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Springで始めるWebApplication / Start Spring Web Application

D98762c822b683773188e826a00d243e?s=47 yachiy
November 20, 2019
61

Springで始めるWebApplication / Start Spring Web Application

D98762c822b683773188e826a00d243e?s=128

yachiy

November 20, 2019
Tweet

Transcript

  1. 4QSJOHͰ࢝ΊΔ 8FCΞϓϦέʔγϣϯ

  2. ·ͣॳΊ͸ͱΓ͋͑ͣ৮ͬͯಈ͔͢

  3. IUUQTTUBSUTQSJOHJP 4QSJOHΞϓϦέʔγϣϯΛ࢝ΊΔʹ͋ͨͬͯ؆୯ʹ਽ܗ Λ࡞Δ͜ͱ͕Ͱ͖Δެࣜ

  4. (SBEMFͷϓϩδΣΫτͱͯ͠࡞੒ ˞(SBEMFʹ͍ͭͯ͸ޙड़ ݴޠ͸+BWBΛ࢖༻ 4QSJOH#PPUͷόʔδϣϯ͸Λ࢖༻ ύοέʔδ໊ʹͳΔ ΞϓϦέʔγϣϯ໊

  5. 4QSJOH8FCΛ࢖͍͍ͨͷͰݕࡧ ϘοΫεʹʮ8FCʯͱ͍Εɺ 4QSJOH8FCΛબ୒ ԡԼ͢Δͱμ΢ϯϩʔυ͕࢝·Δ ʢΞϓϦέʔγϣϯ໊[JQʣ

  6. ల։͢Δͱ͜Μͳײ͡

  7. ࣮͸΋͏ಈ͔ͤΔ

  8. HSBEMFXCPPU3VO ల։ͨ͠σΟϨΫτϦ·ͰλʔϛφϧͰҠಈͯ͠ Λ࣮ߦ

  9. ͜Ε͕ग़͍ͯΕ͹0, (SBEMFͷϓϩάϨεόʔతͳͷ͸ˋͰࢭ·Δ͜ͱ΋͋Δ͔΋ʜ

  10. IUUQMPDBMIPTU

  11.  Τϥʔϖʔδ͕දࣔ͞ΕΔ ˠԿ΋ઃఆ͍ͯ͠ͳ͍ͷͰ౰વͷਖ਼͍͠ڍಈ ͋Θͯͳͯ͘0,

  12.  λϒʹ͸ͪΌΜͱ4QSJOHͷGBWJDPO͕දࣔ͞Ε͍ͯΔ͸ͣ

  13.  ͪͳΈʹCPPU3VO͍ͯ͠ͳ͍ঢ়ଶͰIUUQMPDBMIPTU ʹΞΫηεͯ͠΋ʢ$ISPNFͷ৔߹ʣ͜͏ͳΔͷͰ4QSJOH ͷΤϥʔϖʔδ͕ग़Δͷ͸͏·͘ߦͬͯΔূڌ

  14. ಈ͘͸ಈ͍ͨ

  15. Ͱ΋ͳΜͰಈ͔͘͸Α͘Θ͔Βͳ͍

  16. ݸͣͭݟ͍ͯ͘ Ұؾʹදࣔ͞ΕΔͱ಄·ΘΒͳ͘ͳͬͯ Θ͔Βͳ͘ͳΔͷͰ

  17. ࠶ܝ

  18. ·ͣ͜͜

  19. None
  20. ൴Β͸Ϗϧυπʔϧͱ͍͍·͢

  21. ϏϧυπʔϧJTԿ

  22. Ϗϧυʹؔ͢Δ͜ͱΛΑ͠ͳʹ΍ͬͯ͘ΕΔ

  23. wίϯύΠϧ wςετ w੩తղੳ wϥΠϒϥϦͷґଘ؅ཧ FUDʜ ΋͠Ϗϧυπʔϧ͕ͳ͔ͬͨΒʜ ϑΝΠϧͣͭखͰKBWBDίϚϯυୟ͍ͯ ίϯύΠϧͨ͠Γςετ࣮ߦͨ͠Γʜ ࣗ෼ͰݸͣͭϥΠϒϥϦམͱ͖ͯͯ͠ Ϋϥεύε௨ͨ͠Γʜ

  24. ͪΐͬͱ୤ઢ

  25. खಈͰ+BWBϑΝΠϧΛίϯύΠϧ͢Δʹ͸

  26. )FMMP8PSMEKBWB public class HelloWorld { public static void main(String[] args)

    { System.out.println("Hello World!"); } } ˢͷϑΝΠϧΛAKBWBD)FMMP8PSMEKBWBAͰίϯύΠϧ ˠ)FMMP8PSMEDMBTT͕ੜ੒͞ΕΔ ˠAKBWB)FMMP8PSMEAΛ࣮ߦ ˠ)FMMP8PSME͕ग़ྗ͞ΕΔ
  27. ݸݸ+BWBϑΝΠϧΛίϯύΠϧͯ͠ΫϥεϑΝΠϧ Λੜ੒͢Δͷ͸͠ΜͲ͍ ·ͱΊͯ໘౗ݟͯ͘ΕΔϏϧυπʔϧΛར༻͠ͳ͍ख͸ͳ͍

  28. ศརͳͷͰੋඇϏϧυπʔϧΛ׆༻͍͖͍ͯͨ͠

  29. ͡Ό͋Կ͕ҧ͏ͷ͔ ˠهड़͕ҧ͏ɺͰ͖Δ͜ͱ͕ҧ͏ʢࠩҟ͸ׂѪʣɺྺ࢙͕ҧ͏

  30. ޙൃ ˠଞͷϏϧυπʔϧͷ͍͍ͱ ͜ΖΛٵऩͯ͠஀ੜ

  31. ࠓ͔Β࢝ΊΔͳΒ(SBEMFͰྑ͍ʢݸਓͷײ૝Ͱ͢ʣ

  32. ࣍͜͜

  33. ࠓճ͸ Ͱॻ͚͘Ͳ ΍ Ͱ΋4QSJOHΛར༻Ͱ͖Δʢࠞࡏ΋Մʣ

  34. ࣍͜͜

  35. όʔδϣϯʹΑͬͯαϙʔτ͍ͯ͠Δ w +BWBͷόʔδϣϯ w ґଘ͍ͯ͠ΔϥΠϒϥϦͷόʔδϣϯ ౳͕ҧͬͨΓ͢Δ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUXJLJ ࡉ͔͍ࠩҟ͸ϦϦʔεϊʔτΛࢀর

  36. ࣍͜͜

  37. (SPVQ "SUJGBDUˠQBDLBHF DPNZBDIJZTQSJOH JOUSPEVDUJPO DPNZBDIJZTQSJOHJOUSPEVDUJPO ΞϓϦέʔγϣϯͷݖརݩ΍ॴଐɺ ؅ཧମ੍౳ ΞϓϦέʔγϣϯ໊ ഑ԼʹιʔεΛهड़͍ͯ͘͠

  38. ࣍͜͜

  39. Α͘࢖͏ґଘؔ܎ͱͬ͘͟Γ֓ཁʢओ؍ʣ 4QSJOH8FC 8FCαʔϏεΛͭ͘ΔͨΊʹ༻͍Δجૅత ͳػೳ 4QSJOH%BUB+1" σʔλϕʔε΁ͷ઀ଓɺೖग़ྗɺσʔλૢ࡞ ͳͲʹؔ͢Δػೳ -PNCPL (FUUFS 4FUUFS౳ͷهड़ΛΞϊςʔγϣϯΛ

    ॻ͘͜ͱͰলུͰ͖Δ
  40.  ݱঢ়ʢ࠶ܝʣ

  41. )FMMP8PSME΍͍ͬͯ͘

  42. ͨΊʹ·ͣ͸։ൃ؀ڥΛ४උ͢Δ

  43. +BWB 4QSJOH (SBEMFͳ։ൃʹ͸ ͕͓͢͢Ί $PNNVOJUZΤσΟγϣϯͳΒແྉ ʢͦͯ͠ී௨ʹ࢖͏෼ʹ͸ࠔΒͳ͍ʣ

  44. ิ׬͕ϦΞϧλΠϜ ίʔυδΣωϨʔτ͕ॆ࣮͍ͯ͠Δ ϓϥάΠϯ΋๛෋ ผͷݴޠͷऔΓѻ͍΋ָ FUDʜɹɹɹ ͓͢͢ΊϙΠϯτʢओ؍ʣ Λଧͬͨͱ͖ʹ͸΋͏͜Ε͕ग़ͯΔ

  45. IUUQTXXXKFUCSBJOTDPNJEFBEPXOMPBE ͓࢖͍ͷ04Λબ୒ ͪ͜ΒΛબ୒

  46. μ΢ϯϩʔυ͕ऴΘͬͨΒΠϯετʔϥʹ ैͬͯΠϯετʔϧ

  47. ىಈ

  48. ॳճͳͷͰಛʹJNQPSU͢Δ ઃఆ͸ͳ͍͸ͣ

  49. ࢖͏ςʔϚΛબ୒ɻ ͨͩഎܠࠇͷ΄͏͕ѹ౗తʹ໨ʹ༏͍͠ͷͰͦΕΒΛਪ঑ ˠ͋ͱ͸ͣͬͱ/FYU͔Βͷ4UBSUVTJOHJOUFMMJK*%&"Λબ୒

  50. ͪ͜ΒΛબ୒ 0QFOΛ͓ͨ͠Β4QSJOH*OJUJBMJ[SͰੜ੒ͨ͠ ϓϩδΣΫτʢϑΥϧμʣΛબ୒

  51. ͜ͷνΣοΫϘοΫε֎͢ͱ ىಈͷ౓ʹग़ͯ͜ͳ͘ͳΔ 5JQT͕ग़͖ͯͨΒோΊͯ΋ྑ͍͔΋ ཁΒͳ͚Ε͹$MPTF

  52. ࠷ॳ͸TZODͱͳ͍ͬͯͯಡΈࠐΈ ऴΘΔͱTVDDFTTGVMʹͳΔ

  53. ᶃ ᶄ ᶅ ൪߸ͷॱ൪Ͱԡ͍ͯ͘͠ ͱCPPU3VO͕Ͱͯ͘Δɻ ͜ΕΛԡ͢ͱίϚϯυ ͰHSBEMFXCPPU3VO͠ ͨͷͱಉ༷ʹΞϓϦέʔ γϣϯΛىಈͰ͖Δ

  54. ։ൃ؀ڥͷ४උ׬ྃ

  55. վΊͯ)FMMP8PSME

  56. IUUQMPDBMIPTUʹΞΫηε͢Δͱ )FMMP8PSMEͱը໘ʹग़ྗ͍ͨ͠

  57. None
  58. !4QSJOH#PPU"QQMJDBUJPO ˠ෇༩ͨ͠Ϋϥε͕4QSJOH#PPUͷΞϓϦέʔγϣϯͰ͋Δ͜ͱΛද͢

  59. !4QSJOH#PPU"QQMJDBUJPO ˠ෇༩ͨ͠Ϋϥε͕4QSJOH#PPUͷΞϓϦέʔγϣϯͰ͋Δ͜ͱΛද͢
 ˠ!$POpHVSBUJPO !&OBCMF"VUP$POpHVSBUJPO  !$PNQPOFOU4DBOͳͲΛ෇༩ͨ͠ͷͱಉٛ

  60. ࣮ࡍத਎͜Μͳײ͡

  61. ˠ DPOUSPMMFSύοέʔδΛ࡞Δ

  62. $POUSPMMFSˠਓؒͱγεςϜͷڥք

  63. ˠ )FMMP8PSME$POUSPMMFS ΫϥεΛ࡞੒

  64. Ͱ͖ͨΫϥεʹॲཧΛهड़͍ͯ͘͠

  65. package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/")

    public class HelloWorldController { @GetMapping("") public String helloWorld() { return "Hello World"; } } Ͱ͖ͨΒCPPU3VOͯ͠IUUQMPDBMIPTUʹΞΫηε
  66. ղઆ

  67. )FMMP8PSME͕ग़ྗ͞ΕΔ

  68. package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/")

    public class HelloWorldController { @GetMapping("") public String helloWorld() { return "Hello World"; } }
  69. !3FTU$POUSPMMFS ˠ8FC"1*༻ʢ+TPO౳ͷσʔλΛฦ͢ʣͷίϯτϩʔϥͰ࢖༻ ˠ໭Γ஋͸ίϯςϯπʢ+TPOͱ͔9.-ͳͲ͕Α͘༻͍ΒΕΔʣ

  70. package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/")

    public class HelloWorldController { @GetMapping("") public String helloWorld() { return "Hello World"; } }
  71. !3FRVFTU.BQQJOH ˠ!3FRVFTU.BQQJOHͷҾ਺ͷύεʹΞΫηε͞ΕͨΒर͏ ˠϝιουͰ͸ͳ͘$POUSPMMFSΫϥεࣗମʹ͚ͭΔ͜ͱͰϝιο υͰͷ.BQQJOHͷهड़Λলུͯ͠ॻ͚Δ

  72. package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/")

    public class HelloWorldController { @GetMapping("") public String helloWorld() { return "Hello World"; } }
  73. !(FU.BQQJOH ˠ(FUͰࢦఆ͞ΕͨύεʹΞΫηε͞ΕͨΒर͏ ˠ!3FRVFTU.BQQJOH WBMVFlQBUIz NFUIPE3FRVFTU.FUIPE(&5 Ͱ΋ಉ͡

  74. ࣮ݧ package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController

    @RequestMapping("/hello") public class HelloWorldController { @GetMapping("/hello1") public String helloWorld1() { return "Hello World1"; } @GetMapping("/hello2") public String helloWorld2() { return "Hello World2"; } }
  75. ˠ☓ IFMMPˠ☓ IFMMPˠ☓ IFMMPˠ☓ IFMMPIFMMPˠ)FMMP8PSME IFMMPIFMMPˠ)FMMP8PSME ͜͏ͳΔ͸ͣʜ

  76. 㱻 package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController

    @RequestMapping("/hello") public class HelloWorldController { @GetMapping("/hello1") public String helloWorld1() { return "Hello World1"; } @GetMapping("/hello2") public String helloWorld2() { return "Hello World2"; } } package com.yachiy.spring.introduction.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { @GetMapping("/hello/hello1") public String helloWorld1() { return "Hello World1"; } @RequestMapping(value = “/hello/hello2”, method = RequestMethod.GET) public String helloWorld2() { return "Hello World2"; } } ಉ͜͡ͱΛ࣮ݱͯ͠Δ ˠͩͬͨΒࠨͷ΄͏͕Θ͔Γ΍͍͢
  77. )FMMP8PSMEऴΘΓ

  78. ࣍͸ը໘Λฦ͢

  79. plugins { id 'org.springframework.boot' version '2.1.8.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE'

    id 'java' } group = 'com.yachiy.spring' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' testImplementation 'org.springframework.boot:spring-boot-starter-test' } CVJMEHSBEMF ґଘؔ܎ͷ௥ՃΛ͍ͨ͠৔߹͸EFQFOEFODJFTʹ௥Ճ͍ͯ͘͠
  80. ˠςϯϓϨʔτΤϯδϯ ˠ਽ܗͷ)5.-ʹ4QSJOHଆͷϩδοΫΛຒΊࠐΉͨΊͷ΋ͷͱ ࠓ͸ཧղ͓͚ͯ͠͹0, 5IZNFMFBG ৄ͘͠͸ IUUQTXXXUIZNFMFBGPSHEPDUVUPSJBMTVTJOHUIZNFMFBG@KBIUNM

  81. package com.yachiy.spring.introduction.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public

    class HelloWorldController { @GetMapping("/") public String hello(Model model) { model.addAttribute("value", "͜Μʹͪ͸"); return "hello"; } } )FMMP8PSME$POUSPMMFSKBWB
  82. package com.yachiy.spring.introduction.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public

    class HelloWorldController { @GetMapping("/") public String hello(Model model) { model.addAttribute("value", "͜Μʹͪ͸"); return "hello"; } } )FMMP8PSME$POUSPMMFSKBWB !3FTU$POUSPMMFSˠ!$POUSPMMFS Ҿ਺ʹ.PEFMΛड͚औΔ ଐੑʹ,FZͱ7BMVFΛ௥Ճ
  83. !$POUSPMMFS ˠը໘Λฦ͢ίϯτϩʔϥͰ࢖༻ ˠ໭Γ஋͸7JFXͷભҠઌ ˠࠓճͷ৔߹͸IFMMPΛฦ٫͍ͯ͠ΔͷͰ UFNQMBUFTIFMMPIUNM͕ର৅

  84. ˠը໘ʹ஋Λड͚౉ͨ͢ΊͷΠϯλʔϑΣʔε ˠNPEFMBUUSJCVUF LFZ WBMVF Λݺͼग़ͯ͠஋Λड͚౉͢ ˠଞͷड͚౉͠ํ͸ҎԼͷυΩϡϝϯτࢀর IUUQTEPDTTQSJOHJPTQSJOHEPDTDVSSFOUKBWBEPDBQJ PSHTQSJOHGSBNFXPSLVJ.PEFMIUNM .PEFM

  85. SFTPVSDFTUFNQMBUFT഑ԼʹIFMMPIUNMΛ࡞੒ ˠSFTPVSDFTUFNQMBUFT͕ςϯϓϨʔτஔ͖৔ ˠωετ΋ՄೳʢྫɿUFNQMBUFTHSPVQ UFNQMBUF/BNFIUNMʣ

  86. <!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" /> <title>Hello Thymeleaf</title>

    </head> <body> <h1 th:text="${value}"></h1> </body> </html> IFMMPIUNM
  87. <!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" /> <title>Hello Thymeleaf</title>

    </head> <body> <h1 th:text="${value}"></h1> </body> </html> \LFZ^ͰWBMVFΛࢀরͰ͖Δ IFMMPIUNM
  88. ͜ΕͰCPPU3VOˠMPDBMIPTUʹΞΫηε͢Δͱʜ

  89. ౉ͨ͠จࣈྻ͕ը໘ʹදࣔ͞ΕΔ͜ͱΛ֬ೝ

  90. ը໘ͷදࣔ·Ͱ͸Ͱ͖ͨ

  91. ·ͱΊ

  92. 4QSJOHΛ࢖ͬͯ؆୯ͳ8FCΞϓϦέʔγϣϯΛߏஙͨ͠ ˠ࣍͸ۀ຿ΞϓϦέʔγϣϯͷҰൠతͳΞʔΩςΫνϟͰ͋Δ ૚ΞʔΩςΫνϟʹֶ͍ͭͯͿʢͱ͍͍͔΋ʣ