您好我有一个非持久域的实体列表,因为它具有两个实体的组合属性。我通常使用
def c = Case.createCriteria()
def caseList = c.list( [max: criteria.max, offset: criteria.offset]
但这在我的列表中不起作用,因为获取数据是差异。我必须先从表A中获取数据,然后将其与表B中的数据相结合,然后我将每个数据循环以创建一个新的实体。看下面的代码。
if(criteria.caseNoteType==0)
{
caseNoteList = searchClaimNotesByClaimNote(criteria)
for (CaseNote n: caseNoteList)
{
note = new ClaimNote()
note.dateAssigned = new SimpleDateFormat("yyyy-MM-dd").format(n.cmCaseIdCmCase.assignedDate) //n.cmCaseIdCmCase.assignedDate
note.claimOwner = n.cmCaseIdCmCase.employeeIdEmployee.formatName()
note.caseNoteType = "Claim Notes"
note.caseNoteTitle = n.caseNoteTitle
note.noteOwner = n.employeeIdEmployee.formatName()
note.claimNo = n.cmCaseIdCmCase.id
note.clientName= n.cmCaseIdCmCase.clientIdClient.formatLastNameFirstNameMiddleInit()
note.caseNoteText = n.caseNoteText
note.id = n.id
claimNotesList.add(note)
}
cmcaseList = searchClaimNotesByCaseComments(criteria)
for (CmCase n: cmcaseList)
{
note = new ClaimNote()
note.dateAssigned = new SimpleDateFormat("yyyy-MM-dd").format(n.assignedDate) // n.assignedDate
note.claimOwner = n.employeeIdEmployee.formatName()
note.caseNoteType = "Case Comments"
note.caseNoteTitle = n.caseTitle
note.noteOwner = n.employeeIdEmployee.formatName()
note.claimNo = n.id
note.clientName= n.clientIdClient.formatLastNameFirstNameMiddleInit()
note.caseNoteText = n.caseComment
note.id = n.id
claimNotesList.add(note)
}
}
def cmCaseListFinal = null
def cmCaseCount = claimNotesList.size()
if ('caseNoteType' == criteria.sort ) {
cmCaseListFinal = claimNotesList.sort { a, b ->
if ( 'asc' == criteria.order ) a?.caseNoteType <=> b?.caseNoteType
else b?.caseNoteType <=> a?.caseNoteType
}
} else if ('dateAssigned' == criteria.sort ) {
cmCaseListFinal = claimNotesList.sort { a, b ->
if ( 'asc' == criteria.order ) a?.dateAssigned <=> b?.dateAssigned
else b?.clientIdClient?.dateAssigned <=> a?.dateAssigned
}
} else {
cmCaseListFinal = claimNotesList
}
return cmCaseListFinal
}
这是用标准搜索的代码。同样与其他实体合并。
def searchClaimNotesByCaseComments(ClaimNoteSearchCriteria criteria)
{
log.info ( criteria )
def c = CmCase.createCriteria()
def cmCaseList = c.list([max: criteria.max, offset: criteria.offset] )
{
createAlias("clientIdClient", "client")
createAlias("employeeIdEmployee", "employee")
createAlias("internalOrgIdInternalOrg", "InternalOrg")
if ( criteria.clientSsnSearch != null && criteria.clientSsnSearch.trim() != '' ) {
criteria.clientSsnSearch = criteria.clientSsnSearch.trim()
like('client.clientSsnSearch', criteria.clientSsnSearch)
}
//C#
if ( criteria.clientVaFileNbrSearch != null && criteria.clientVaFileNbrSearch.trim() != '' ) {
criteria.clientVaFileNbrSearch = criteria.clientVaFileNbrSearch.trim()
eq ( 'client.clientVaFileNbrSearch', criteria.clientVaFileNbrSearch.toString() )
}
// Service Number
if ( criteria.clientMilitaryServiceNbr != null && criteria.clientMilitaryServiceNbr.trim() != '' ) {
criteria.clientMilitaryServiceNbr = criteria.clientMilitaryServiceNbr.trim()
like ( 'client.clientMilitaryServiceNbr', ( criteria.clientMilitaryServiceNbr as String).trim() + '%' )
}
// Last Name
if ( criteria.clientLastName != null && criteria.clientLastName != '' ) {
like ( 'client.clientLastName', (criteria.clientLastName as String).trim() + '%' )
}
// FirstName
if ( criteria.clientFirstName != null && criteria.clientFirstName != '' ) {
like ( 'client.clientFirstName', (criteria.clientFirstName as String).trim() + '%' )
}
// employeeIdEmployee
if ( criteria.employeeIdEmployee != null ) {
eq ( 'employee.id', criteria.employeeIdEmployee )
}
//poaStatus
if ( criteria.intOrgLegalName != null && criteria.intOrgLegalName != '' ) {
like ( 'InternalOrg.intOrgLegalName', (criteria.intOrgLegalName as String).trim() + '%' )
}
if ( criteria.caseNoteText != null && criteria.caseNoteText != '' ) {
like( 'caseComment', (criteria.caseNoteText as String).trim() + '%' )
}
}
return cmCaseList
}
这是我的分页代码
<div class="gadgetLong">
<div> <span class="gadgetName"><g:message code="claimSearch.searchResult.label" default="Search Results" /></span><span class="gadgetNumber">${ claimNoteList.size() }</span></div>
<span class="gadgetNumber">${ claimNoteList.size() }</span>
<span class="gadgetNumber"> <g:paginate next="Next" prev="Back"
maxsteps="0" action="sortclaimSearch"
total="${ claimNoteList.size() }" /></span>
</div>
<div>
我想在不使用创建条件的情况下将分页添加到最终列表中,因为它已经过了搜索。有没有解决这个问题?或者我在做什么?感谢
答案 0 :(得分:3)
也许你可以使用一个方法获取一个子列表并在视图中将子列表作为列表进行渲染,并将list.size()作为总数...在服务中可能是这样的(无论你想要什么):
def getSubList(List objectList, Map params) {
//verify params
try {
params.max = params.max.toInteger()
params.offset = params.offset.toInteger()
} catch (Exception exceptionInstance) {
params.max = 10
params.offset = 0
}
//Verify pagination params... if not you add them
if (params.max <= 0) {
params.max = 10
}
//Get total size of the list
def objectInstanceTotal = objectList.size()
//verify offset.
if (params.offset < 0 || params.offset > objectInstanceTotal) {
params.offset = 0
}
//Verify the pagination border (don't excess from array border).
Integer bordeInteger = params.max + params.offset
if (bordeInteger > objectInstanceTotal) {
bordeInteger = objectInstanceTotal
}
//Extract the sublist based on the pagination.
def objectSubList = objectList.subList(params.offset, bordeInteger)
return objectSubList
}
在控制器中:
def list = {
def list = //Define your list
def subList = service.getSubList(list, params)
[list: subList, listInstanceTotal: list.size()]
}
在视图中,您可以像往常一样调用de list action
希望这会有所帮助;)