Spring Roo 更新密码字段或不更新所有字段

发布于 2024-12-20 08:58:26 字数 407 浏览 4 评论 0原文

我有一个实体User,它有用户名name等...

User也有一个密码属性。我在列表/显示表单中禁用了它的呈现,但在更新表单中,字段设置为 type="password"

让我烦恼的是,如果不重新输入密码,就无法更新用户,因为那里没有星星,如果不输入密码,password 将设置为 null""

我怎样才能绕过它?

还有一个问题。如果我从更新表单中删除某些字段,则所有其他字段都将设置为 null。 我想要的是使用户能够更新某些实体的某些字段,但不是所有字段。

I have an entity User that has username, name, etc ...

User also has a password property. And I disabled rendering of it in list/show forms, but in the update form, field is set to type="password".

What bugs me is that you can't update user without re-entering password as no stars are there, and if you don't enter the password, password is set to null or "".

How can I bypass that?

There is also another issue. If I remove some fields from update form, all other fields are set to null.
What I want is to enable user to update some, but not all fields of some entitiy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2024-12-27 08:58:26

我创建了一个实体 Foo,其中包含四个字段 f1、f2、f3f4

在该实体的 update.jspx 中,我为字段 f1 设置了属性 render="false"

FooController 更新方法中,在更新 foo 参数对象之前,我从数据库中获取旧值并将其粘贴到参数 foo 中,如下所示,因为我们不希望最终用户更新此字段。

    Foo fromDB=Foo.findFoo(foo.getId());
    foo.setF1(fromDB.getF1());
    foo.merge();

我能够验证 Foo 实体中 f1 的旧值在更新操作完成后没有发生更改。

这可能是阻止用户更新实体对象中某些字段的一种方法,希望这种方法适合您。

干杯,

I created an entity Foo with four fields f1,f2, f3 and f4.

In update.jspx for this entity, I set the attribute render="false" for field f1.

In the FooController update method, before the foo parameter object was updated, I fetched the old value from the db and stick it in the parameter foo, as shown below, because we do not want the end user to update this field.

    Foo fromDB=Foo.findFoo(foo.getId());
    foo.setF1(fromDB.getF1());
    foo.merge();

I am able to verify that old value for f1 in Foo entity is not getting changed after the update operation was completed.

This could be one way to prevent users from updating some fields in an entity object and hope this approach works for you.

Cheers,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文