mdoTomofumi Chiba
1/20/2025, 9:59:48 AM

Spring R2DBC: SQLベタ書き

こんな感じ?

@Repository
@RequiredArgsConstructor
public class EmployeeRepository {

    private static final BeanPropertyRowMapper<Employee> mapper = new BeanPropertyRowMapper<>(Employee.class);

    private final DatabaseClient databaseClient;

    public Mono<Employee> find(final String id) {
        return this.databaseClient.sql("""
                SELECT id, name
                FROM employee
                WHERE id = :id
                """)
                .bind("id", id)
                .map(mapper)
                .one();
    }
}
TweetBlueskyLike