Home>

I am developing a web application with Spring Boot.
I want to implement the search function, but I cannot implement it well.
NullPointerException occurs when you search from the search screen.
I think I haven't got the value well, but I'm not sure why.

If there is someone who understands the problem area, I would like to ask a professor.

Applicable source code
package com.example.demo.domain.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.domain.model.Product;
import com.example.demo.domain.repository.ProductDao;
@Service
public class ProductService {
    @Autowired
    ProductDao dao;
(Omitted)
    public List<Product>search (String productCode, String productName, int price) {
        List<Product>result = dao.findAll ();
        return result;
    }
}
package com.example.demo.domain.model;
import lombok.Data;
@Data
public class Product {
    private String productCode;// product code
    private String productName;// product name
    private int price;// price
}
package com.example.demo.domain.repository;
import java.util.List;
import org.springframework.dao.DataAccessException;
import com.example.demo.domain.model.Product;
public interface ProductDao {
(Omitted)
public List<Product>findAll () throws DataAccessException ;;
}
package com.example.demo.domain.jdbc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.example.demo.domain.model.Product;
import com.example.demo.domain.repository.ProductDao;
@Repository
public class ProductDaoJdbcImpl implements ProductDao {
    @Autowired
    JdbcTemplate jdbc;
(Omitted)
    @Override
    public List<Product>findAll () throws DataAccessException {
        return null;
    }
}
<! DOCTYPE html PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns: th = "http://www.thymeleaf.org"
      xmlns: layout = "http://www.ultraq.net.nz/thymeleaf/layout">
<head>
   <meta http-equiv = "Content-Type" content = "text/html;charset = UTF-8"></meta>
</head>
  <body>

        
             Product search screen 
        
      <form method = "post" action = "/ search">
      <table>
        <tr><td>Product code:<input type = "text" name = "productCode" th: value = "${productCode}" /></td></tr>
        <tr><td>Product name:<input type = "text" name = "productName" th: value = "${productName}" /></td></tr>
        <tr><td>Price:<input type = "text" name = "price" th: value = "${price}" /></td></tr>
        <tr><td><input type = "submit" value = "Search" /></td></tr>
      </table>
    </form>
         0}"><label th: text = "${resultSize}"></label>cases 
    <table border = "1" th: if = "${resultSize>0}">
      <tr>
        <td>Product ID</td>
        <td>Product name</td>
        <td>price</td>
      </tr>
      <tr th: each = "data: ${result}">
        <td th: text = "${data.productCode}" />
        <td th: text = "${data.productName}" />
        <td th: text = "${data.price}" />
      </tr>
    </table>
    
  </body>
</html>
Supplementary information

The database used is "H2".