首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jspx中的Roo隐藏字段

Jspx中的Roo隐藏字段
EN

Stack Overflow用户
提问于 2011-05-16 23:12:45
回答 3查看 1.8K关注 0票数 1

我想在jspx文件中有一个隐藏字段。

我想要做的是自动将经过身份验证的用户名保存到数据库中。我是这样做的:

使用以下命令修改我的bean:

代码语言:javascript
复制
 public void Got.setUserkt(String userkt) {
        final String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
        this.userkt = currentUser;
    }

环顾四周,我发现我不得不在我的create.jspx页面中使用render=" false“,但是当render设置为false时,我的输入字段中的任何数据都不会保存在数据库中。

我做错了什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-17 17:36:55

我会继续我所做的,为了我的新秀伙伴们。

第一步:从我的roo控制器(EntityController_Roo_Controller.aj)中截取我的方法

代码语言:javascript
复制
  @RequestMapping(method = RequestMethod.POST)

    public String create(@Valid Got got, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {

        if (bindingResult.hasErrors()) {

            uiModel.addAttribute("got", got);

            addDateTimeFormatPatterns(uiModel);

            return "gots/create";

        }

        uiModel.asMap().clear();

        got.persist();

        return "redirect:/gots/" + encodeUrlPathSegment(got.getId().toString(), httpServletRequest);

    }

第二步:将方法粘贴到java控制器(EntityController.java)中

第三步:编辑方法以获取usernmae并使用它修改我的方法

  1. 添加了主体作为参数
  2. update my entity : got.setUserkt(principal.getName());

@请求映射(method= RequestMethod.POST)

公共字符串create(@Valid got,BindingResult bindingResult,模型uiModel,HttpServletRequest httpServletRequest,主体主体){ if (bindingResult.hasErrors()) { uiModel.addAttribute(" Got ",got);addDateTimeFormatPatterns(uiModel);return "gots/create";} uiModel.asMap().clear();got.setUserkt(principal.getName());got.persist();return "redirect:/gots/“+ encodeUrlPathSegment(got.getId().toString(),httpServletRequest);}

再次感谢!

票数 2
EN

Stack Overflow用户

发布于 2011-05-16 23:23:34

为什么不创建一个方面来拦截保存目标实体并添加相应的字段,或者通过将其复制到*.java控制器并在其中添加字段来覆盖Spring Controller中的相应方法呢?

票数 1
EN

Stack Overflow用户

发布于 2014-07-08 19:31:03

disableFormBinding和类型的组合应该可以工作,如下所示。

注意:不确定它是否是这样设计的:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6019428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档