I have a sql questions table. The table accordingly contains Questions objects. Each object contains the question and answer strings.
package com.example.kr2db.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Objects;
@Entity
public class Question {
@Id
@GeneratedValue
private int id;
private String question;
private String answer;
public Question() {
}
public Question(String question, String answer) {
this.question = question;
this.answer = answer;
}
In the repository interface, I need a method that will search the table for a Question object containing a word or phrase from the question or answer string. How do I do this?
I use List findQuestionByQuestionContainsIgnoreCase(String question); but it's not exactly what I need. Because let's say the word "rat" is present in the table and in the question line, but if I write "rats", then such a query does not work.
package com.example.kr2db.repository;
import com.example.kr2db.model.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface QuestionRepository extends JpaRepository<Question, Integer> {
List<Question> findQuestionByQuestionContainsIgnoreCase(String question);
}