Java back-end server programming; includes various exercises
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

  1. package com.example.sqltest;
  2. import java.math.BigDecimal;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.boot.CommandLineRunner;
  6. import org.springframework.boot.SpringApplication;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  9. import org.springframework.context.annotation.Bean;
  10. import com.example.sqltest.model.Customer;
  11. import com.example.sqltest.model.CustomerDAOImpl;
  12. @SpringBootApplication
  13. public class SqlTestApplication extends SpringBootServletInitializer {
  14. private static final Logger logger = LoggerFactory.getLogger(SqlTestApplication.class);
  15. public static void main(String[] args) {
  16. SpringApplication.run(SqlTestApplication.class, args);
  17. }
  18. @Bean
  19. public CommandLineRunner CustomerRunner(CustomerDAOImpl customerDAO) {
  20. return (args) -> {
  21. logger.info("Deleting old database table entries");
  22. customerDAO.dropAll();
  23. logger.info("Creating new database table entries");
  24. customerDAO.save(new Customer(
  25. "Daniel", "Thyssenlauf",
  26. "man", "English",
  27. new BigDecimal("0.45"),
  28. "danthyf@gmail.com", null
  29. ));
  30. customerDAO.save(new Customer(
  31. "Janina", "Riikanen",
  32. "woman", "Finnish",
  33. new BigDecimal("1.74"),
  34. "janskuuu@yahoo.com", "+358405341242"
  35. ));
  36. logger.info("Created a new database table with the following values");
  37. for (Customer customer : customerDAO.findAll()) {
  38. logger.info("CUSTOMER table: {}", customer.toString());
  39. }
  40. };
  41. }
  42. }