zsy001 发表于 2018-10-24 08:19:07

grails中直接使用SQL语句

ApplicationContext ctx = (ApplicationContext) ApplicationHolder.getApplication().getMainContext()  
      def dataSource = ctx.getBean('dataSource')
  
      def sql = new Sql(dataSource)
  
      String strSql = "select * from company"
  
      sql.eachRow(strSql) {
  
          println it
  
          println it.id
  
      }
  
      //需要导包
  
      import groovy.sql.Sql
  
      import org.codehaus.groovy.grails.commons.ApplicationHolder
  
      import org.springframework.context.ApplicationContext


页: [1]
查看完整版本: grails中直接使用SQL语句