spring mvc : @ModelAttribute

This commit is contained in:
haerong22
2021-04-07 18:48:48 +09:00
parent e7f18d930b
commit 6d09b99ca1
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package com.example.springmvc.basic;
import lombok.Data;
@Data
public class HelloData {
private String username;
private int age;
}

View File

@@ -1,7 +1,9 @@
package com.example.springmvc.basic.request;
import com.example.springmvc.basic.HelloData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -75,4 +77,18 @@ public class RequestParamController {
log.info("username={}, age={}", paramMap.get("username"), paramMap.get("age"));
return "ok";
}
@ResponseBody
@RequestMapping("/model-attribute-v1")
public String modelAttributeV1(@ModelAttribute HelloData helloData) {
log.info("helloData={}", helloData);
return "ok";
}
@ResponseBody
@RequestMapping("/model-attribute-v2")
public String modelAttributeV2(HelloData helloData) {
log.info("helloData={}", helloData);
return "ok";
}
}