Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用spring boot在控制器中显示sqlite数据_Java_Spring_Spring Boot_Sqlite_Javafx - Fatal编程技术网

Java 如何使用spring boot在控制器中显示sqlite数据

Java 如何使用spring boot在控制器中显示sqlite数据,java,spring,spring-boot,sqlite,javafx,Java,Spring,Spring Boot,Sqlite,Javafx,我想使用JDBCTemplate显示sqlite数据,并将它们放在一个变量上,所有这些都放在控制器的initialize方法上 这是我的代码: application.properties spring.datasource.url=jdbc:sqlite:sqlitesample.db spring.datasource.driver-class-name=org.sqlite.JDBC customer.java package com.mkyong.customer; public cla

我想使用JDBCTemplate显示sqlite数据,并将它们放在一个变量上,所有这些都放在控制器的initialize方法上 这是我的代码:

application.properties
spring.datasource.url=jdbc:sqlite:sqlitesample.db
spring.datasource.driver-class-name=org.sqlite.JDBC

customer.java

package com.mkyong.customer;
public class Customer {

    private int ID;
    private String name;
    private Integer age;
    private String createdDate;

    public Customer() {
    }

    public Customer(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Customer(int ID, String name, Integer age, String createdDate) {
        this.ID = ID;
        this.name = name;
        this.age = age;
        this.createdDate = createdDate;
    }

    @Override
    public String toString() {...
    }
getter and setter
    

customerRepository.java

@Repository
public class CustomerRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    
public List<Customer> findAll() {

        String sql = "SELECT * FROM CUSTOMER";

        List<Customer> customers = new ArrayList<>();

        List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);

        for (Map row : rows) {
            Customer obj = new Customer();

           obj.setID(((Number) row.get("ID")).intValue());
        
            obj.setName((String) row.get("NAME"));
            obj.setAge(((BigDecimal) row.get("AGE")).intValue());
            
            obj.setCreatedDate((String) row.get("CREATED_DATE"));
            customers.add(obj);
        }

        return customers;
    }
startapplication


@SpringBootApplication
public class StartApplication extends Application{
    
    public static Stage stage;
    public static Stage getStage() { return stage; }
    
     @Override
    public void start(Stage primaryStage) throws Exception{

        Parent root = FXMLLoader.load(getClass().getResource("welcome.fxml"));
       
        stage=primaryStage;
        primaryStage.setTitle("VetoBooks.Com");
        primaryStage.setScene(new Scene(root, 400, 400));
        primaryStage.show();
       
    }
     public static void main(String[] args) {
            Application.launch();
        }

        @Override
        public void init() {
            SpringApplication.run(getClass()).getAutowireCapableBeanFactory().autowireBean(this);
        }
}

如何打印customerRepository.findAll(),因为它打印错误请。。您几乎已经找到了,但缺少完整的stacktrace:)

@SpringBootApplication
public class StartApplication extends Application{
    
    public static Stage stage;
    public static Stage getStage() { return stage; }
    
     @Override
    public void start(Stage primaryStage) throws Exception{

        Parent root = FXMLLoader.load(getClass().getResource("welcome.fxml"));
       
        stage=primaryStage;
        primaryStage.setTitle("VetoBooks.Com");
        primaryStage.setScene(new Scene(root, 400, 400));
        primaryStage.show();
       
    }
     public static void main(String[] args) {
            Application.launch();
        }

        @Override
        public void init() {
            SpringApplication.run(getClass()).getAutowireCapableBeanFactory().autowireBean(this);
        }
}