如何在Playframework中更新模型的特定字段? [英] How do I update a certain field of a Model in Playframework?
本文介绍了如何在Playframework中更新模型的特定字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有一个User类,如果我想更新它的名称:
Suppose we have a User class, if I want to update it's name:
User user = User.findById(123); user.name =某人"; user.save();
User user = User.findById(123); user.name = "someone"; user.save();
生成的SQL将是
update user as user0 set user0.name = ? user0.email = ? .....
这意味着Play
并没有意识到我只想更新一个字段.有什么办法可以使生成的SQL仅更新指定的字段?
That means Play
didn't realize I just want to update a single field. Is there any way could make the generated SQL only update the specified fields ?
推荐答案
信息:这是Play 2 + Ebean的答案!因此它不适用于Play 1 + JPA
Ebean的API 中有一些选项,因此您应该检查并选择一个:
There are some options in Ebean's API, so you should check it and choose one:
Update<T>
- check in the sample for@NamedUpdates
annotationEbean.createUpdate(beanType, updStatement)
SqlUpdate
- you can just perform raw SQL update, without need for giving the entity type
这篇关于如何在Playframework中更新模型的特定字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文