BSPS BSPS MyBatis FormatterA VS Code extension that automatically formats MyBatis XML mapper files. It formats SQL inside MyBatis tags using proper indentation and configurable style options. Features
UsageOpen any
To set BSPS MyBatis Formatter as the default formatter for XML files, add the following to your
ConfigurationAll settings are available under Settings > Extensions > BSPS MyBatis Formatter or in
|
| Value | Description | Example |
|---|---|---|
"after" (default) |
Trailing comma at end of line | a, → next line |
"before" |
Leading comma at start of line | , b on each line |
"after" (trailing)
SELECT
user_id,
user_name,
email
FROM users
"before" (leading)
SELECT
user_id
, user_name
, email
FROM users
mybatis-formatter.keywordCase
Controls the casing of SQL keywords.
| Value | Description | Example |
|---|---|---|
"upper" (default) |
Uppercase keywords | SELECT, FROM, WHERE |
"lower" |
Lowercase keywords | select, from, where |
"preserve" |
Keep original casing | unchanged |
mybatis-formatter.indentation
The indentation string used for XML and SQL formatting.
| Value | Description |
|---|---|
" " (default) |
4 spaces |
" " |
2 spaces |
"\t" |
Tab |
Example settings.json
{
"mybatis-formatter.commaPosition": "before",
"mybatis-formatter.keywordCase": "upper",
"mybatis-formatter.indentation": " "
}
Example
Before formatting:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.UserMapper">
<select id="findUser" resultType="User">
select u.user_id, u.user_name, u.email from users u where u.user_id = #{userId} and u.status = 'ACTIVE'
</select>
</mapper>
After formatting (commaPosition: "after")
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.UserMapper">
<select id="findUser" resultType="User">
SELECT
u.user_id,
u.user_name,
u.email
FROM users u
WHERE
u.user_id = #{userId}
AND u.status = 'ACTIVE'
</select>
</mapper>
After formatting (commaPosition: "before")
<select id="findUser" resultType="User">
SELECT
u.user_id
, u.user_name
, u.email
FROM users u
WHERE
u.user_id = #{userId}
AND u.status = 'ACTIVE'
</select>