0
Good morning, I am trying to make a fulltext in mysql with spring boot, in mysql when I do the test with the sql command, the result brings back correctly, but when I pass the spring boot sql Native, it brings an empty list.
Positionrepository
@Query(nativeQuery = true, value = "SELECT * FROM position WHERE MATCH (name, area) AGAINST (':description' IN BOOLEAN MODE)")
List<Position> searchByNameAndArea(@Param("description") String name);
Positionservice
public List<Position> searchByNameAndArea(String name) {
return positionRepository.searchByNameAndArea(name);
}
Positioncontroller
@GetMapping("/search")
public List<Position> searchByNameAndArea(@RequestParam String name) {
return positionService.searchByNameAndArea(name);
}
After I run the project, I walk into the bank and turn the remote
ALTER TABLE position ADD FULLTEXT (NAME, AREA);
URL used in Postman
localhost:8080/position/search?name=position
Model da Position
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Entity
@Table(name = "position")
public class Position {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;
@NotNull
private String name;
@NotNull
private String area;
}
Could someone help me, please.
How is the mapping of the Position class
– Bruno Roberto
I updated the question with Model.
– Murylo Capucho
From what I noticed the sql command is not able to catch the name I pass as parameter, because if I leave the automatic word without parameter, it can bring the result.
– Murylo Capucho
@Query(nativeQuery = true, value = "SELECT * FROM position WHERE MATCH (name, area) AGAINST ('position' IN BOOLEAN MODE)")
– Murylo Capucho