From fd45fe2a6a53f54d0348fc9a95267400c513e635 Mon Sep 17 00:00:00 2001 From: haerong22 Date: Thu, 8 Apr 2021 02:01:41 +0900 Subject: [PATCH] spring mvc : http response - static, view template --- .../response/ResponseViewController.java | 30 +++++++++++++++++++ .../resources/templates/response/hello.html | 10 +++++++ 2 files changed, 40 insertions(+) create mode 100644 spring-mvc/springmvc/src/main/java/com/example/springmvc/basic/response/ResponseViewController.java create mode 100644 spring-mvc/springmvc/src/main/resources/templates/response/hello.html diff --git a/spring-mvc/springmvc/src/main/java/com/example/springmvc/basic/response/ResponseViewController.java b/spring-mvc/springmvc/src/main/java/com/example/springmvc/basic/response/ResponseViewController.java new file mode 100644 index 00000000..c7371afb --- /dev/null +++ b/spring-mvc/springmvc/src/main/java/com/example/springmvc/basic/response/ResponseViewController.java @@ -0,0 +1,30 @@ +package com.example.springmvc.basic.response; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class ResponseViewController { + + @RequestMapping("/response-view-v1") + public ModelAndView responseViewV1() { + ModelAndView mav = new ModelAndView("response/hello") + .addObject("data", "hello!"); + + return mav; + } + + @RequestMapping("/response-view-v2") + public String responseViewV2(Model model) { + model.addAttribute("data", "hello!"); + + return "response/hello"; + } + + @RequestMapping("/response/hello") + public void responseViewV3(Model model) { + model.addAttribute("data", "hello!"); + } +} diff --git a/spring-mvc/springmvc/src/main/resources/templates/response/hello.html b/spring-mvc/springmvc/src/main/resources/templates/response/hello.html new file mode 100644 index 00000000..28817115 --- /dev/null +++ b/spring-mvc/springmvc/src/main/resources/templates/response/hello.html @@ -0,0 +1,10 @@ + + + + + Title + + +

empty

+ + \ No newline at end of file