When we use JDBC, if we write all the SQL statements in the Java file, because Java does not support here document, the multiline string either uses the plus sign or the Java 8
String.join()
method to connect, while not syntax highlighting for SQL statements, so the SQL string is poorly read. Don't say why not just write the original SQL statements without Hibernate, or use the jdbctemplate when operating a complex system.
So we want to be able to write the SQL statements in a separate*.sql
File, so many editors can highlight the syntax, or you can get smart hints when typing. There is a way to*.sql
As a property file, the SQL statement that defines multiple rows in it is
Select.user=select ID, FirstName, LastName, address \
from users \
where id=?
It can be used after loadinggetProperty("select.user")
To refer to the corresponding statement. The Wrap property file is the same as Bash\
, but so, then*.sql
Not a pure SQL file, not correct syntax highlighting, once the SQL comments are written--
It's even more of a troublemaker.
So our second scenario is: first*.sql
It should be a real SQL file, not a spoofed property file, so how do we represent the individual keys in order to be able to reference each SQL statement in the program? The inspiration here still comes from the Linux shell, which specifies the execution environment in the Linux shell in a special way.#!
Such as
#!/bin/bash
#!/usr/bin/env python
Read the full text >>
Write SQL statements in the. sql file in the Spring project