0
我有兩個控制器:timeheetcontroller和顧問控制器。在時間表我有場:使用belongsTo字段的條件返回空結果
class Timesheet {
...
String orderNumber
String groupCode
static belongsTo = [consultant: Consultant] //here
...
而且在顧問:
class Consultant {
...
String userName
...
如何建立一個查詢,將由顧問的名稱進行篩選時間表的名單?我正在嘗試類似下面的內容,但它不起作用。
獲取顧問的名字:
<input type="text" id="consultant" name="consultant" value="${flash.consultant}"/>
而且在TimesheetController:
def list = {
flash.consultant = params.consultant //here
flash.groupCode = params.groupCode
flash.orderNumber = params.orderNumber
if(!params.max) {
params.max = 20
}
def query
def criteria = Timesheet.createCriteria()
def results
query = {
and{
like("userName", '%' + params.consultant + '%') //here
like("groupCode", '%' + params.groupCode + '%')
like("orderNumber", '%' + params.orderNumber + '%')
}
}
results = criteria.list(params, query)
render(view:'index', model:[ timesheetInstanceList: results ])
}
任何想法?
使用此代碼,沒有錯誤,但結果不正確。返回timesheetInstanceList中的所有值,而不僅僅是具有輸入顧問名稱的記錄。 – user3245082
在dataSource配置文件中更改loggingSql = true並在此檢查/粘貼sql generated.also也輸出params.consultant,params.groupCode和params.orderNumber的值 –
Hibernate:select TOP(?)this_.timesheet_id as timeshee1_6_0_,this_.consultant_id as consulta2_6_0_ ,this_.group_code as group5_6_0_,this_.order_no as order7_6_0_ as total9_6_0_ from eci_timesheets this_ where(this_.group_code like?and this_.order_no like?) Hibernate:選擇this_.consultant_id作爲consulta1_1_0_,this_.user_id作爲user6_1_0_,this_.user_name作爲user7_1_0_來自eci_consultants this_ – user3245082