一个属性使用多行的java属性文件
我将sql存储在一个属性文件中,并使用spring将其注入。这是可行的:一个属性使用多行的java属性文件,java,spring,properties,Java,Spring,Properties,我将sql存储在一个属性文件中,并使用spring将其注入。这是可行的: someSQL = select result from myTable where y = 2 and x = ? order by z 但为了便于阅读,我希望: someSQL = select result from myTable where y = 2 and x = ? order
someSQL = select result from myTable where y = 2 and x = ? order by z
但为了便于阅读,我希望:
someSQL = select result
from myTable
where y = 2
and x = ?
order by z
我需要使用的正确文本格式是什么?使用\在行的末尾,如
someSQL = select result \
from myTable \
where y = 2 \
and x = ? \
order by z
另外,要注意后面的空格,因为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
事实上,非常重要的一点是告诉大家,“\”之后的不能是任何内容,甚至不能是一个空格 对新行使用\并确保每行前面有一个空格\
someSQL = select result \
from myTable \
where y = 2 \
and x = ? \
order by z \
如果没有给定一个空格,输出将如下所示
someSQL = select result\
from myTable\
where y = 2\
and x = ?\
order by z\
someSQL=select resultfrom myTablewhere y = 2and x = ?order by z
这将导致
Java级别:Java.sql.SQLSyntaxErrorException
和DB-level
缺少关键字
这实际上应该是一个注释,而不是一个答案。这是对其他项目的一个很好的补充,解决了我的问题。非常感谢。