Created
September 15, 2019 17:28
-
-
Save dubeboy/c38cfc148d5a1a079a66507907774ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package za.co.dubedivine.groceryapp.config | |
import org.springframework.boot.CommandLineRunner | |
import org.springframework.stereotype.Component | |
import za.co.dubedivine.groceryapp.model.GroceryItem | |
import za.co.dubedivine.groceryapp.repository.GroceryItemRepository | |
import javax.persistence.PrePersist | |
@Component | |
class DBHelper(private val groceryRepository: GroceryItemRepository) : CommandLineRunner { | |
@PrePersist | |
fun deleteAllBeforeSaving() { | |
groceryRepository.deleteAll() | |
} | |
@Throws(Exception::class) | |
override fun run(vararg args: String?) { | |
val items = listOf( | |
GroceryItem("Beans", true), | |
GroceryItem("Eggs", false), | |
GroceryItem("Milk", true), | |
GroceryItem("Cheese", true) | |
) | |
groceryRepository.saveAll(items) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment