Skip to content

Instantly share code, notes, and snippets.

@deeev-sb
Last active December 24, 2020 19:44
Show Gist options
  • Save deeev-sb/0d613a9e7f73520d6dabd510ecaa7d75 to your computer and use it in GitHub Desktop.
Save deeev-sb/0d613a9e7f73520d6dabd510ecaa7d75 to your computer and use it in GitHub Desktop.
// java/hello/hellospring/controller/HelloController.java
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
// Controller 사용 시 @Controller라고 Annotation을 추가해야 함
@Controller
public class HelloController {
// 웹 애플리케이션에서 /hello 라고 들어오면 아래 method를 호출
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data", "hello!");
return "hello";
}
// MVC를 위해 추가
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello-template";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment