Project Root
└─src
└─ main
└─ java
└─ com.example
└─ demo
└─DemoApplication
└─SampleApplication
DemoApplicaton.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
@RequestMapping("/") //D'où vient-il?/"Est-ce que http://localhost:8080/Pointer vers
String index(){
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
SampleApplicaton.java
package com.example.hoge;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class SampleController {
@RequestMapping(value = "/", method = RequestMethod.GET)
//Recevoir lorsqu'une requête arrive à la racine de l'URL
//DemoApplication et root (=8080) est couvert
public String index(Model model) {
model.addAttribute("message", "Hello World!!");
return "index";
}
}
Project Root
└─src
└─ main
└─ java
└─ com.example
└─ demo
└─DemoApplication
└─ hoge
└─SampleApplication
DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
@RequestMapping("/hoge")
String index(){
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Whitelabel Error Page
SampleApplicaton.java
package com.example.hoge;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class SampleController {
@RequestMapping(value = "/bar", method = RequestMethod.GET)
public String index(Model model) {
model.addAttribute("message", "Hello World!!");
return "index";
}
}
Recommended Posts