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

Springで始めるWebApplication / Start Spring Web App...

yachiy
November 20, 2019
120

Springで始めるWebApplication / Start Spring Web Application

yachiy

November 20, 2019
Tweet

Transcript

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

    { System.out.println("Hello World!"); } } ˢͷϑΝΠϧΛAKBWBD)FMMP8PSMEKBWBAͰίϯύΠϧ ˠ)FMMP8PSMEDMBTT͕ੜ੒͞ΕΔ ˠAKBWB)FMMP8PSMEAΛ࣮ߦ ˠ)FMMP8PSME͕ग़ྗ͞ΕΔ
  2. ࣮ݧ 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"; } }
  3. 㱻 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"; } } ಉ͜͡ͱΛ࣮ݱͯ͠Δ ˠͩͬͨΒࠨͷ΄͏͕Θ͔Γ΍͍͢
  4. 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ʹ௥Ճ͍ͯ͘͠
  5. 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
  6. 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Λ௥Ճ
  7. <!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