最近在格式化代碼時,發現代碼中mybatis的mapper文件內sql語句都無法格式化,sql內的關鍵字也沒有變色並且大寫,查看自己設置如下圖都沒錯,在sql中使用alt+enter也沒有提示Language Injection Setting,並且在設置中始終無法找到這個配置選項。
網上關於sql格式化的文章基本都是基於有這個選項進行的,idea版本是2018.3,都是激活後的,搜索一番無果後只能去idea官方網站需求幫助,https://www.jetbrains.com/help/idea/language-injections-settings.html,在這個地方開始就很好的提示了想使用Language Injection Setting需要開啓一個插件IntelliLang:
Language Injections
File | Settings | Editor | Language Injections for Windows and Linux
IntelliJ IDEA | Preferences | Editor | Language Injections for macOS
Ctrl+Alt+S the Settings/Preferences icon
For the Language Injections page to be available, the IntelliLang plugin must be enabled. (This plugin is bundled with the IDE and enabled by default.)
在自己的插件中這個IntelliLang果然沒有開啓,不知道怎麼給關閉了,開啓後重啓idea,在xml的sql文件中就可以使用alt+enter設置sql格式化了:
保證自己的dtd配置正確,sql中關鍵字都會變色,使用C+A+L格式化代碼也會根據你的設置進行格式化了。