spring mvc : @ModelAttribute
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example.springmvc.basic;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class HelloData {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private int age;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.example.springmvc.basic.request;
|
package com.example.springmvc.basic.request;
|
||||||
|
|
||||||
|
import com.example.springmvc.basic.HelloData;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Controller;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
@@ -75,4 +77,18 @@ public class RequestParamController {
|
|||||||
log.info("username={}, age={}", paramMap.get("username"), paramMap.get("age"));
|
log.info("username={}, age={}", paramMap.get("username"), paramMap.get("age"));
|
||||||
return "ok";
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user