0
groovy 및 grails 내부에서 저장 프로 시저를 호출하는 것과 같은 요구 사항이 있습니다. 나는 Mongodb를 데이터베이스로 사용하고있다. 누구나 저장 프로 시저를 호출하여 단계별로 알려주십시오.grails 및 groovy에서 저장 프로 시저를 호출하는 방법
groovy 및 grails 내부에서 저장 프로 시저를 호출하는 것과 같은 요구 사항이 있습니다. 나는 Mongodb를 데이터베이스로 사용하고있다. 누구나 저장 프로 시저를 호출하여 단계별로 알려주십시오.grails 및 groovy에서 저장 프로 시저를 호출하는 방법
Grails 서비스에서이 작업을 수행 할 수 있습니다.
// Inject a data source:
def dataSource //or def dataSource_<other named DS name>
def serviceMethod() {
Sql sql = new Sql(dataSource_messages)
def sqlCall = "exec sp_name :param1, :param2"
final paramMap = [param1: new Timestamp(dateFrom.time), param2: new Timestamp(dateTo.time)]
log.info "Running: $sqlCall with params $paramMap"
def rows = []
try {
rows = sql.rows(sqlCall, paramMap)
} catch (Exception e) {
log.warn "Could not execute ${sqlCall} with params ${paramMap}: ${e.getMessage()}", e
}
rows
}
선택적으로하는 개체를 명령로 변환 :
rows.collect { row -> new MyCmd(row) }
public class MyCmd {
String spField1
String spField2
Date dateTime
}
을