🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### ViewType ViewType 类似Jackson的@View注解,在BeetlSQL查询过程中,查询被VIewType申明的字段,如下TestUser,属性myId和myName被@View注解标注,因此sqlManager指定viewType为KeyInfo.class的时候,仅仅查询此俩列 ```java TestUser keyInfo = sqlManager.viewType(TestUser.KeyInfo.class).unique(TestUser.class, 1); @Data public static class TestUser { public static interface KeyInfo { } @Column("id") @AutoID @View(KeyInfo.class) Integer myId; @Column("name") @View(KeyInfo.class) String myName; Integer departmentId; } ``` VIewType会影响代码生成,因此对于TestUser对象来说,根据主键查询会有俩条内置sql语句生成,参考代码AbstractDBStyle ```java public SQLSource genSelectByIds(Class<?> cls,Class viewType) { ConcatContext concatContext = this.createConcatContext(); Select select = concatContext.select(); appendIdsCondition(cls,select); select.from(cls); if(viewType!=null){ select.all(cls,viewType); }else{ select.all(); } return new SQLTableSource(select.toSql()); } ``` 对于普通的sql'语句,也可以只映射部分查询结果,而不需要映射所有结果集,比如某些大字段(TODO,未完成)