Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java intellij multiple line strings

I am currently devving in inttelij for java, being a phpstorm user previously I am used to setting up strings the span multiple lines like this (which I am aware is incorrect Java syntax):

@Query("select count(*) from table where
        value= :xxx
        AND value= :xxx2")

when it expects to be set up like this:

@Query("select count(*) from table where "+
       "value= :xxx "+
       "AND value2 =:xxx2)

Is there some kind of string editor plugin I can use on intelliJ, or some kind of code formatting option I can use to make this more or less like phpstorm?

like image 452
Paul Stanley Avatar asked Sep 16 '26 18:09

Paul Stanley


2 Answers

I can edit a query and maintain its formatting for a Mysql query string by going Alt+Enter -> Inject Language/Reference Mysql then Alt+Enter again -> Edit Mysql fragment on the injected fragment.

like image 93
Paul Stanley Avatar answered Sep 19 '26 07:09

Paul Stanley


No. This is Java, not PHP so the way string literals are represented in source code is defined very strictly by the Java Language Specification.

It is a compile-time error for a line terminator to appear after the opening " and before the closing matching ".

But all modern IDEs help by breaking the string correctly if you press Enter within a string literal.

(By the way, your query string is wrong, as it reads select count(*) from table wherevalue=...)

like image 45
biziclop Avatar answered Sep 19 '26 09:09

biziclop