Adding initialization data via Bootstrap.groovy to the application

My domain layer is as follows:

@Resource(uri='/product') class BasicProduct { String title String description Double price Date creationDate Date changedDate static constraints = { //everything is by default NotNull title(blank: false, unique: true) description(blank: false) price(blank: false, inList: [5,15,25,50,100]) creationDate(min: new Date()) } } 

My Bootstrap.groovy contains this code:

 class BootStrap { def init = { servletContext -> new BasicProduct(title: "Product1", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:5).save() new BasicProduct(title: "Product2", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:75).save() new BasicProduct(title: "Product3", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:50).save() new BasicProduct(title: "Product4", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:25).save() new BasicProduct(title: "Product5", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:15).save() println "initializing data..." } 

However, when I open the URL \product , I do not see any data.

Any ideas why?

I appreciate your answer!

+6
source share
1 answer

For your dates you can do:

 Date dateCreated Date lastUpdated static mapping = { autoTimestamp true } 
+5
source

All Articles