2013-07-11 1 views

답변

2

grails-app/conf/resources에 json 파일을 넣고 Bootstrap.groovy을 편집했습니다.

if (!Cars.count()) { 
     // add cars 
     def filePath = "resources/carsData.json" 
     def text = grailsApplication.getParentContext().getResource("classpath:$filePath").getInputStream().getText() 
     def json = JSON.parse(text) 

     for (carData in json) { 
      def c = new Cars(
       name: carData ["name"], 
       year: carData ["year"] 
      ).save(failOnError: true); 
     } 
    } 
+0

내가보다는 비 정렬 화를 통해이 작업을 수행하기 위해 노력했습니다 : 내가 데이터를로드 나중에

class BootStrap { def grailsApplication ... 

그리고 : 파일의 맨 위에

, 나는 Grails 애플리케이션을 주입 이 수동 접근. 어떤 아이디어로 그렇게 할 수 있습니까? –

관련 문제