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("/") //Woher bekommst du es? "/“Ist http://localhost:8080/Zeigen auf
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)
//Empfangen, wenn eine Anfrage im Stammverzeichnis der URL eingeht
//DemoApplication und root (=8080) ist abgedeckt
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