

[前の質問](https://ja.stackoverflow.com/q/83209/2808)で上手くいったので、テーブルを変えて実行してみようとしましたが、上手く行きません。

何が原因でしょうか。

[code]

    package com.example.demo.mysql;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    import lombok.Getter;
    import lombok.Setter;
    
    @Entity
    @Table(name="user")
    @Getter
    @Setter
    public class Employee {
      @Id
      @Column(name="ID")
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private String ID;
      @Column(name="PASS")
      private String PASS;
      @Column(name="NAME")
      private String NAME;
      @Column(name="KANA")
      private String KANA;
    }
    
[/code]

[code]

    package com.example.demo.mysql;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.servlet.ModelAndView;
    
    @Controller
    public class DemoController {
    
      @Autowired //別のクラスを使えるようにしてくれるもの
      EmployeeRepository empRepository;
    
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String index(Model model) {
        List<Employee> emplist = empRepository.findAll();
        model.addAttribute("employeelist", emplist);
        return "index";
      }
    
      @GetMapping("/search")
      public ModelAndView search(@RequestParam String NAME, ModelAndView mav) {
        List<Employee> list = empRepository.findByempnameLike("%" + NAME + "%");
        mav.addObject("list", list);
        mav.setViewName("/search");
        return mav;
      }
    }
    
[/code]

[code]

    package com.example.demo.mysql;
    
    import java.util.List;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;
    
    @Repository
    public interface EmployeeRepository extends JpaRepository<Employee, String> {
    
      List<Employee> findByempnameLike(String string);
    
    
    }
    
[/code]

[code]

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:th="http://www.thymeleaf.org">
    <head>
    <title>indexhtml</title>
    <meta charset="utf-8" />
    </head>
    <body>
     <form action="/search" method="get">
      名前： <input type="text" name="NAME"> <input type="submit"
       value="送信">
     </form>
     <table>
      <tr th:each="emp : ${employeelist}" th:object="${emp}">
    <td th:text="*{ID}"></td>
       <td th:text="*{NAME}"></td>
      </tr>
     </table>
    </body>
    </html>
    
[/code]

[code]

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
    <head>
    <title>searchhtml</title>
    <meta charset="utf-8" />
    </head>
    <body>
      <table>
      <tr><th>コード</th><th>商品名</th></tr>
        <tr th:each="emp : ${list}" th:object="${emp}">
          <td th:text="*{ID}"></td>
          <td th:text="*{NAME}"></td>
        </tr>
      </table>
    </body>
    </html>
    
[/code]

[code]

    spring.datasource.url=jdbc:mysql://localhost:3306/xxx
    spring.datasource.username=root
    spring.datasource.password=xxx
    spring.jpa.database=MYSQL
    spring.jpa.hibernate.ddl-auto=update
    
[/code]

エラー文

[code]

    Error creating bean with name 'demoController': Unsatisfied dependency expressed through field 'empRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository' defined in com.example.demo.mysql.EmployeeRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.example.demo.mysql.EmployeeRepository.findByempnameLike(java.lang.String)! Reason: Failed to create query for method public abstract java.util.List com.example.demo.mysql.EmployeeRepository.findByempnameLike(java.lang.String)! No property empname found for type Employee!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.example.demo.mysql.EmployeeRepository.findByempnameLike(java.lang.String)! No property empname found for type Employee!
    
[/code]

[![画像の説明をここに入力](https://i.stack.imgur.com/mD2T8.png)](https://i.stack.imgur.com/mD2T8.png)

mysqlは画像のとおりです。


CC BY-SA 4.0
2021-10-25T09:43:50.327
83251
2021-10-26T04:19:53.870
2021-10-26T04:19:53.870
3060
48247
question
java mysql spring-boot
Spring boot 部分一致検索　何がおかしいのか分からない


`Employee` エンティティクラスのフィールド名に合わせて `EmployeeRepository`
インタフェースのメソッド名も変える必要があります。

`NAME` フィールドに対する部分一致検索を行うためのメソッド名は `findByNAMELike` になります。

[code]

      @GetMapping("/search")
      public ModelAndView search(@RequestParam String NAME, ModelAndView mav) {
        List<Employee> list = empRepository.findByNAMELike("%" + NAME + "%");
        mav.addObject("list", list);
        mav.setViewName("/search");
        return mav;
      }
    
[/code]


CC BY-SA 4.0
2021-10-25T13:37:41.897
83255
2021-10-25T13:37:41.897
2808
83251
answer