我有 3 个域类
Class Application {
Candidate candidate;
Vote vote;
static belongsTo = [candidate:Candidate,vote:Vote]
}
Class Candidate {
String username;
static hasMany =[capplications:Application]
}
Class Vote {
String name;
Date startdate;
Date enddate;
static hasMany =[capplications:Application]
}
我有一个服务类,其中包含一个显示投票名称的方法
class ApplicationService {
def serviceMethod() {
}
def candidatesByVName(def vname){
def results = Candidature.createCriteria().list() {
createAlias("candidat","candidatAlias")
createAlias("vote","voteAlias")
eq('voteAlias.name',vname)
projections {
// property('votes.name')
property('candidatAlias.username')
}
}
return results
}
def candidatsGrpByVte(){
def results = Application.withCriteria {
createAlias("vote", "vote")
projections {
groupProperty("vote.name")
}
}
return results;
}
}
我从控制器开始
class ApplicationController{
def applicationService;
def displayVote={
def votes=applicationService.candidatsGrpByVte()
return [VoteList:votes]
}
def displayCandByVote={
def candidate=applicationService.candidatesByVName(params.vote)
}
}
我想在视图中显示每个投票的候选人列表