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("/") //From which address do you get it? "/“Is http://localhost:8080/Point to
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)
//Receive when a request comes to the root of the URL
//DemoApplication and root (=8080) is covered
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