Skip to main content
Hint

This article is generated by AI translation.

@Segment Annotation

Marks an interface method to define a reusable SQL fragment. The method name becomes the fragment name, which can be referenced in other SQL via the @{macro,fragmentName} rule.

Example: reuse a column list via SQL fragment
@SimpleMapper
public interface UserMapper {
// The method name user_do_allColumns becomes the SQL fragment name
@Segment("user_uuid, user_name, login_name, login_password, email, seq, register_time")
void user_do_allColumns();

// String arrays are also supported; elements are joined with spaces
@Segment({"user_uuid, user_name, login_name,",
"login_password, email, seq, register_time"})
void user_do_allColumns2();

// Reference the SQL fragment defined above via @{macro,user_do_allColumns}
@Insert({ //
"insert into user_info (@{macro,user_do_allColumns})", //
"values (#{userUuid}, #{name}, #{loginName}, #{loginPassword}, #{email}, #{seq}, #{registerTime})" })
int createUser(UserInfo tbUser);
}
Tip

Methods annotated with @Segment typically return void. The method is never actually called; it only serves as a carrier for the SQL fragment.

Properties

PropertyDescription
value必选 The SQL fragment content (supports string arrays, joined by spaces).