Nim*_*sky 28 java spring properties
我将sql存储在属性文件中,并使用spring注入它,这有效:
someSQL = select result from myTable where y = 2 and x = ? order by z
Run Code Online (Sandbox Code Playgroud)
但为了便于阅读,我想要这个:
someSQL = select result
from myTable
where y = 2
and x = ?
order by z
Run Code Online (Sandbox Code Playgroud)
我需要使用哪种正确的文本格式?
Man*_*noj 54
在行尾使用\就像
someSQL = select result \
from myTable \
where y = 2 \
and x = ? \
order by z
Run Code Online (Sandbox Code Playgroud)
此外,请注意任何尾随空格,因为Java在组装行时会查找连续的反斜杠+换行符.
换句话说:反斜杠必须是换行符之前的最后一个字符.
你添加\(斜杠)继续下一行.属性文件将是这样的 -
prop1=first line of prop1 \
second line of prop1\
third line of prop1
prop2=first line of prop2 \n \
second line of prop2 \n \
third line of prop2
Run Code Online (Sandbox Code Playgroud)
使用\ 换行并确保每个\前有一个空格
someSQL = select result \
from myTable \
where y = 2 \
and x = ? \
order by z \
Run Code Online (Sandbox Code Playgroud)
如果没有给出一个空格,输出将是这样的
someSQL = select result\
from myTable\
where y = 2\
and x = ?\
order by z\
someSQL=select resultfrom myTablewhere y = 2and x = ?order by z
Run Code Online (Sandbox Code Playgroud)
这会导致
Java级别: java.sql.SQLSyntaxErrorException
和数据库级别 Missing Keyword