跳至主要內容

基本类型查询

xuejmnet大约 3 分钟

基本类型查询

easy-query提供了针对基本类型的查询功能,如果您只需要返回基本类型那么不需要额外定义复杂的对象,并且支持map等数据结构

String

List<String> list2 = easyEntityQuery.queryable(Topic.class)
                .where(f -> f.id().eq("1"))
                .select(s -> new StringProxy(s.id()))
                .toList();

List<String> list2 = easyEntityQuery.queryable(Topic.class)
                .where(f -> f.id().eq("1"))
                .select(s -> s.id())//eq 2.x.x^
                //.selectColumn(s -> s.id())
                .toList();

==> Preparing: SELECT t.`id` FROM `t_topic` t WHERE t.`id` = ?
==> Parameters: 1(String)
<== Time Elapsed: 2(ms)
<== Total: 1

Integer

List<Integer> list2 = easyEntityQuery.queryable(Topic.class)
                .where(f -> f.id().eq( "1"))
                .select(s -> new IntegerProxy(s.stars()))
                .toList();

List<Integer> list2 = easyEntityQuery.queryable(Topic.class)
                .where(f -> f.id().eq( "1"))
                .select(s -> s.stars())//eq 2.x.x^
                //.selectColumn(s -> s.stars())
                .toList();

==> Preparing: SELECT t.`stars` FROM `t_topic` t WHERE t.`id` = ?
==> Parameters: 1(String)
<== Time Elapsed: 2(ms)
<== Total: 1

Map

返回结果为Map<String,Object> ,默认Key忽略大小写(Locale.ENGLISH)

List<Map<String,Object>> list2 = easyEntityQuery.queryable(Topic.class)
                    .where(f -> f.id().eq( "1"))
                    .select(s -> new MapProxy().adapter(r->{
                        r.put("id",s.id());
                        r.put("name",s.stars());
                    }))
                    .toList();

==> Preparing: SELECT t.`id` AS `id`,t.`stars` AS `name` FROM `t_topic` t WHERE t.`id` = ?
==> Parameters: 1(String)
<== Time Elapsed: 2(ms)
<== Total: 1

List<Map<String,Object>> list2 = easyEntityQuery.queryable(Topic.class)
                    .where(f -> f.id().eq( "1"))
                    .select(s -> new MapProxy().selectAll(s))
                    .toList();
==> Preparing: SELECT t.`id`,t.`stars`,t.`title`,t.`create_time` FROM `t_topic` t WHERE t.`id` = ?
==> Parameters: 1(String)
<== Time Elapsed: 2(ms)
<== Total: 1


List<Map<String,Object>> list2 = easyEntityQuery.queryable(table)
                    .where(f -> f.id().eq( "1"))
                    .select(s -> new MapProxy())
                    .toList();


==> Preparing: SELECT * FROM `t_topic` t WHERE t.`id` = ?
==> Parameters: 1(String)
<== Time Elapsed: 9(ms)
<== Total: 1

支持的类型

类型是否支持
String
BigDecimal
Boolean
Byte[]
Byte
Double
Float
Integer
LocalDate
LocalDateTime
LocalTime
Long
Map
Short
java.sql.Date
Time
Timestamp
java.util.Date
上次编辑于:
贡献者: Hoysing,xuejiaming