其他分享
首页 > 其他分享> > WebMvc常用注解示例

WebMvc常用注解示例

作者:互联网

WebMvc常用注解示例

示例代码

@Controller
public class HelloWorldController {
    @RequestMapping("")
    public String index(@RequestParam(required = true) int value, Model model) {
        return "index";
    }
}
@ControllerAdvice(assignableTypes = HelloWorldController.class)
public class HelloWorldControllerAdvice {
    @ModelAttribute("acceptLanguage")
    public String acceptLanguage(@RequestHeader("Accept-Language") String acceptLanguage){
        return acceptLanguage;
    }
    @ModelAttribute("jsessionId")
    public String jsessionId(@CookieValue("JSESSIONID") String jsessionId){
        return jsessionId;
    }
    @ModelAttribute("message")
    public String message(){
        return "Hello,World";
    }
    @ExceptionHandler(Throwable.class)
    public ResponseEntity<String> onException(Throwable throwable) {
        return ResponseEntity.ok(throwable.getMessage());
    }
}

标签:WebMvc,return,String,示例,jsessionId,ModelAttribute,acceptLanguage,注解,public
来源: https://www.cnblogs.com/fjf3997/p/13041453.html