mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-05 13:17:58 +08:00
feat: SqlBuilder增加一个format方法
This commit is contained in:
parent
ec1e13d3b1
commit
ed9e67318d
@ -609,6 +609,15 @@ public class SqlBuilder implements Builder<String> {
|
||||
return this.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化SQL语句
|
||||
* @return SqlBuilder
|
||||
*/
|
||||
public SqlBuilder format() {
|
||||
this.sql.replace(0, this.sql.length(), SqlFormatter.format(this.sql.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- private method start
|
||||
|
||||
/**
|
||||
|
@ -18,4 +18,11 @@ public class SqlFormatterTest {
|
||||
String format = SqlFormatter.format(sql);
|
||||
System.out.println(format);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqlBuilderFormat() {
|
||||
String sql = "SELECT `link_table_a`.`value_a` AS `link_table_a.value_a`,`link_table_a`.`id` AS `link_table_a.id`,`link_table_b`.`value_b` AS `link_table_b.value_b`,`link_table_c`.`id` AS `link_table_c.id`,`link_table_b`.`id` AS `link_table_b.id`,`link_table_c`.`value_c` AS `link_table_c.value_c` FROM `link_table_a` INNER JOIN `link_table_b` ON `link_table_a`.`table_b_id` = `link_table_b`.`id` INNER JOIN `link_table_c` ON `link_table_b`.`table_c_id` = `link_table_c`.`id`";
|
||||
String format = SqlBuilder.of(sql).format().build();
|
||||
System.out.println(format);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user