- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有兴趣使用 ofbiz 查找今天生日的人。
这是用户的实体:
<entity entity-name="User">
<field name="identifier" type="id-long"></field>
<field name="dateOfBirth" type="date"></field>
</entity>
这是搜索今天生日的用户的损坏代码:
SimpleDateFormat monthDayFormat = new SimpleDateFormat("MM-dd");
Calendar cal = Calendar.getInstance();
String today = monthDayFormat.format(cal.getTime());
List<GenericValue> people = dctx.getDelegator().findList("User",
EntityCondition.makeCondition("dateOfBirth", EntityOperator.LIKE, "%".today),
null, null, null, false);
这显然不起作用,因为我们正在尝试比较字符串和日期对象。
使其工作的另一种尝试是创建一个 View 实体,并将日期转换为两个整数:日和月,或者使用上面的代码将日期转换为字符串。显然,我找不到任何让它发挥作用的方法。
最佳答案
最有效的方法是构建 View 实体。以下定义应该适用于多个数据库(例如 PostgreSQL ),即支持 EXTRACT
的数据库功能:
<view-entity entity-name="UserView">
<member-entity entity-alias="USER" entity-name="User"/>
<alias-all entity-alias="USER"/>
<alias name="dayOfBirth" function="extract-day" entity-alias="USER" field="dateOfBirth"/>
<alias name="monthOfBirth" function="extract-month" entity-alias="USER" field="dateOfBirth"/>
</view-entity>
通过上面的 View ,您可以通过约束两个新字段轻松地执行查询:
List<GenericValue> users = EntityQuery.use(dctx.getDelegator()).from("UserView").where("dayOfBirth", day, "monthOfBirth", month).queryList();
或者,如果您正在编写 Groovy 脚本,则其在 OFBiz DSL 中的等效项:
List<GenericValue> users = from("UserView").where("dayOfBirth", day, "monthOfBirth", month).queryList();
或者,按照完全不同的方法,您可以通过添加“dayOfBirth”和“monthOfBirth”字段(类型为“numeric”)来扩展“User”实体:
<entity entity-name="User">
<field name="identifier" type="id-long"></field>
<field name="dateOfBirth" type="date"></field>
<field name="dayOfBirth" type="numeric"></field>
<field name="monthOfBirth" type="numeric"></field>
</entity>
然后,您可以定义一个 eca 规则来触发服务的执行,以便在每次使用非空 dateOfBirth 字段创建或更新用户记录时填充两个新字段:
<eca entity="User" operation="create-store" event="return">
<condition field-name="dateOfBirth" operator="is-not-empty"/>
<action service="populateDayAndMonthOfBirth" mode="sync"/>
</eca>
populateDayAndMonthOfBirth 服务的服务定义如下所示:
<service name="populateDayAndMonthOfBirth">
<attribute name="identifier" type="String" mode="IN" optional="false"/>
</service>
(请填写缺少的属性,如“引擎”、“位置”和“调用”)。该服务将简单地选择记录,从其 dateOfBirth 字段中提取代表日期和月份的整数,并将它们存储在 dayOfBirth 和 MonthOfBirth 字段中。
关于java - 在 ofbiz 中查找今天生日的人 : how to extract month and day from Ofbiz entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49285834/
如果我在 forms.py 中有: birthdate = forms.DateTimeField() 和 html: 我需要创建一个新的小部件还是有答案?
我正在尝试从 facebook sdk 获取生日,我可以获取我的生日,但我无法从其他帐户获取生日。我已经在“设置”中设置了联系人电子邮件,并在此处回答了一个应用程序供公众使用:Set up app p
我需要存储用户的出生日期。我在前端创建了一个表单,通过 3 个选择下拉菜单获取他们的出生日期年、月和日。我目前将这三个值存储在 SQL 中,并具有相同名称的列。 我需要执行的查询之一是获取高于或低于特
我有 mysql 数据库,以生日列作为日期。 保存到此列的最佳方式是什么,年份是可选的。我应该随便放一些年份吗?在数据库中保存生日的最佳做法是什么。 我在 cakephp 中创建了 3 个文本字段,日
考虑到此代码(基于 Python/Mongoengine),我知道如何找到下一个即将到来的生日 class User(mongoengine.Document): (...) birthday
在以前版本的 Prestashop 1.6 中,注册表单有生日字段的日期选择器和一个下拉列表,我们可以在其中选择月、日、年。 Prestashop 版本 1.6 - 生日截图: 然后在最新版本的Pre
我正在使用带有changeYear 的jquery ui datepicker。问题是它以 block 的形式显示年份(从 1985 年到 2005 年,然后单击 1985 年打开其他年份)我需要显示
我正试图在来自佛蒙特州和纽约的成员(member)的生日表中找到最年长的人。我的成员类似于以下内容: Members ------- MemberID, Firstname, Lastname, Bi
工作中需要用到身份证验证,还要支持检查15位和18位。 我一时手懒,问同事有没有现成的函数可用,同事google了一下,扔给我一个 asp-vbscript版本的函数。 可我这边是客户端j
我正在努力解决以下正则表达式: \b[\dBb][-. \dEe]+(\d{4})\b 它应该匹配帐号,但不匹配 token /生日或其中包含“be”的文本。在 community 的支持下,我成功捕
我有一个简单的小部件,它有: 请注意,今天是生日。因此,它意味着保持相同,无论您身在何处(不应该发生时区)。如果您 1 月 10 日凌晨 3:00 出生在英国,并且在纽约查看您的个人信息,您应该仍然
在我的数据库中,日期存储为 dd/mm/yyyy。当我检索它时,我想将日期分别拆分为字符串日、字符串月和字符串年。我应该怎么做? “/”将是分隔符,对吗? 最佳答案 您需要可以使用DateTime.P
我很难通过 Facebook SDK 获取用户信息。 我正在努力争取生日、工作和教育。 我正在使用这个: let graphRequest : FBSDKGraphRequest = FBSDKGr
我正在尝试使用 NSSortDescriptor 按日期对 NSMutableArray *friends, key:birthday 进行排序,我的 NSLog 中的所有生日都为空,但名称仍在记录中
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在尝试从其 Google Plus 帐户获取用户的信息,包括性别和年龄。由于这些字段可能是私有(private)的,我认为明确请求它们可以解决问题。然而,尽管登录对话框明确指出该应用程序请求查看您
我正在制作一个 facebook 应用程序来显示用户的生日......... 'YOUR_APP_ID', 'secret' => 'Y
我正在尝试将 OAuth2 登录添加到我基于 Node/ExpressJS/MongoDB/PassportJS 构建的应用中。 我用这个方法可以成功登录,但是我无法获取某些信息。我唯一能够访问的是
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我无法让我的代码来获取我的测试帐户的“生日”,甚至我自己的“生日”(任何地方都没有成功!)来回显,尽管从我所看到的来看,我正在正确地请求它并且我拥有适当的权限对于“user_birthday”。 但是
我是一名优秀的程序员,十分优秀!