2012-07-23 77 views
20

我存储SQL的属性文件,并使用弹簧这部作品注入它:Java属性文件使用多行一个属性

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 

什么我需要使用正确的文本格式吗?

回答

39

使用\在该行的像

someSQL = select result \ 
       from myTable \ 
       where y = 2 \ 
       and x = ? \ 
       order by z 

另外结束,当心任何尾部空格的自爪哇组装线时看起来连续反斜杠+换行符。

换句话说:反斜杠必须是换行符前的最后一个字符。

+0

我以为我试过,谢谢 – NimChimpsky 2012-07-23 10:33:42

4

您添加\(斜线)继续下一行。 属性文件会是这样 -

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 
-1

其实这告诉后“\”不能什么都不甚至没有空格是非常重要的!

+1

这实际上应该是一个评论,而不是一个答案 – Sirmyself 2017-11-02 14:21:26