所以我有表格评论和作者。我想用许多可选参数构建复杂的搜索栏。我想使用可选的作者名字/姓氏和一些诸如流行度(基于评论评级)之类的标志来过滤评论。
由于我不知道如何使用 spring 数据 jpa 存储库编写它,我一直在考虑将其编写为带有 @Query 注释的本机查询,这样应该可以工作
Select c.* from comment c join author a on a.id = c.author_id
Where (:firstname = '' or (:firstname = a.firstname))
And (:lastname = '' or (:lastname = a.lastname))
And (:popular = false or (c.rating > 25))
Run Code Online (Sandbox Code Playgroud)
是否可以选择使用 spring 数据 jpa 编写它?
例如,将来我计划添加更多参数和分页。使用 spring 就像 1 分钟的 sql 查询,我将失去几个小时。
在这种情况下是否有一些最佳实践?
如何制作一些可以跳过web所需验证的按钮(但我仍然希望处理所有数据,所以立即等等不可能是真的).
重要的是它必须是普遍的.目前我在每个必需的现场条件下使用一些请求参数.代码示例如下
<p:inputText value="#{cc.attrs.data.exampleData1}"
required="#{param['onlySave'] == null}"/>
<p:inputText value="#{cc.attrs.data.exampleData2}"
required="#{param['onlySave'] == null}"/>
<p:inputText value="#{cc.attrs.data.exampleData3}"
required="#{param['onlySave'] == null}"/>
<p:commandButton value="Zapisz zmiany"
action="#{cc.attrs.controller.save()}"
update="@form">
<f:param name="onlySave" value="true"/>
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
这个解决方案很好,因为我可以在每个页面中将此参数添加到按钮并跳过验证,但是当我的保存按钮没有进行任何重定向时,如果在保存方法中失败了一些java验证,我只是添加了一些没有重定向的消息然后我从输入中丢失了所有必需的样式.
验证失败时是否有可能在保存方法中设置onlySave参数null或者可能是更好的解决方案?
编辑: Balus回答很好,但是使用bean验证:
@Pattern(regexp = "^([^0-9]*)$", message = "only non numbers")
String field;
Run Code Online (Sandbox Code Playgroud)
它处理bean以外的所有数据.最好的只是忽略必需的字段属性,而不是验证等.
EDIT2:
<tr>
<td class="label">
<p:outputLabel id="label" for="#{cc.attrs.componentId}" value="#{cc.attrs.label}"/>
</td>
<td class="value">
<cc:insertChildren/> --here component with componentId
</td>
</tr>
<tr class="errorMessage">
<td class="label"/>
<td class="value">
<p:message id="error" for="#{cc.attrs.componentId}" />
</td>
</tr>
Run Code Online (Sandbox Code Playgroud) 所以我的应用程序基于角度2(角度cli)和一些CMS.页面的某些片段从CMS下载并显示在角度2页面上.主要问题是页眉和页脚来自CMS.所以我想知道如何添加全局解析器(全局非常重要,我不想为应用程序中的每个路径路径添加解析器),这将强制角度等待CMS返回页眉和页脚.我已经成功使用解析器通过实现路由接口等待某些路由上的某些数据
export class InboxResolver implements Resolve<MessageListItem[]>
Run Code Online (Sandbox Code Playgroud)
我在一些自定义路线中使用它:
const MessagesRoutes: Routes = [
{
path: 'inbox',
component: InboxComponent,
resolve: { messages: InboxResolver }
}
];
Run Code Online (Sandbox Code Playgroud)
但是如何在一个地方定义一个全局HeaderAndFooterResolver?
angular ×1
angular-cli ×1
jsf ×1
jsf-2 ×1
primefaces ×1
resolver ×1
spring ×1
spring-boot ×1
sql ×1