
提升IDEA JPA SQL打印可读性
在使用IDEA和JPA时,启用show-sql后,生成的SQL语句常常挤成一行,例如:
<code class="sql">update table set name=?, length_type=?, list_order=?, name=?, type=?, uptime=? where id=?</code>
这不利于阅读和调试。 为了增强可读性,我们希望SQL语句能够格式化,例如:
<code class="sql">SELECT
id, name
FROM
table
WHERE
...
JOIN
...</code>可以通过配置Spring的hibernate.format_sql属性来实现。
在application.properties文件中添加以下配置:
<code class="properties">spring.jpa.properties.hibernate.format_sql=true</code>
或者,在application.yml文件中:
<code class="yaml">spring:
jpa:
properties:
hibernate:
format_sql: true</code>保存配置后,重新启动应用,IDEA控制台打印的SQL语句将自动换行并格式化,显著提高可读性。
以上就是IDEA中如何美化JPA打印的SQL语句?的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号