In my Spring JPA Project, I have a repo file as such:
@Repository
public interface StudentRepository extends JpaRepository<Student, Integer>{
@Query(value = "select * from students", nativeQuery = true)
public List<Student> findStudents(
@Param("keyword") String keyword
);
}
With this, I can still copy paste the SQL and run in my DB software.
But when it comes to large queries as such:
@Query(value = "SELECT\n" +
"*\n" +
"FROM\n" +
"students\n" +
"WHERE\n" +
"(\n" +
"`id` LIKE CONCAT('%', :keyword, '%') OR\n" +
"`name` LIKE CONCAT('%', :keyword, '%') OR\n" +
"`desc` LIKE CONCAT('%', :keyword, '%') OR\n" +
"`sex` LIKE CONCAT('%', :keyword, '%')\n" +
")", nativeQuery = true)
public List<Student> findStudents(
@Param("keyword") String keyword
);
I can't really directly copy paste and run in the DB software, I have to remove the "+" "\n" characters. I've tried Java's """SQL_QUERY_STRING""" but it doesn't allow it.
Are there any alternative approach to this?
UPDATE
I tried the triple double-quote but it gives:
String literal is not properly closed by a double-quote