前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >@ModelAttribute

@ModelAttribute

作者头像
阿超
发布2022-08-16 17:33:58
2350
发布2022-08-16 17:33:58
举报
文章被收录于专栏:快乐阿超

小人之过也必文。——《论语》

如果我们需要在controller执行前做一些事情,除了使用AOP外,我们还可以使用@ModelAttribute注解

@ModelAttribute注解的方法会在controller执行前执行并把结果传递给了下面controller里我们注解的参数

实际开发中可以用来鉴权、过滤参数等

代码语言:javascript
复制
package com.ruben.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ModelController
 * @Description: 我还没有写描述
 * @Date: 2020/12/23 0023 20:36
 * *
 * @author: <achao1441470436@gmail.com>
 * @version: 1.0
 * @since: JDK 1.8
 */
@RestController
@RequestMapping("model")
public class ModelController {

    @ModelAttribute
    public String getWords() {
        return "ruben";
    }

    @GetMapping("whoIsAuthor")
    public String whoIsAuthor(@ModelAttribute String word) {
        return word;
    }

}
image-20201223205811650
image-20201223205811650
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-12-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档