- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Fluent Mybatis实际开发中的优势对比由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
之前文章介绍过了Fluent基本框架等,其中有几个重要的方法用到了IQuery和IUpdate对象。 这2个对象是FluentMybatis实现复杂和动态sql的构造类,通过这2个对象fluent mybatis可以不用写具体的xml文件, 直接通过java api可以构造出比较复杂的业务sql语句,做到代码逻辑和sql逻辑的合一。下面接着介绍如何通过IQuery和IUpdate定义强大的动态SQL语句.
表结构 假如有学生成绩表结构如下
1
2
3
4
5
6
7
8
9
10
11
12
|
create
table
`student_score`
(
id
bigint
auto_increment comment
'主键ID'
primary
key
,
student_id
bigint
not
null
comment
'学号'
,
gender_man tinyint
default
0
not
null
comment
'性别, 0:女; 1:男'
,
school_term
int
null
comment
'学期'
,
subject
varchar
(30)
null
comment
'学科'
,
score
int
null
comment
'成绩'
,
gmt_create datetime
not
null
comment
'记录创建时间'
,
gmt_modified datetime
not
null
comment
'记录最后修改时间'
,
is_deleted tinyint
default
0
not
null
comment
'逻辑删除标识'
) engine = InnoDB
default
charset=utf8;
|
统计2000年到2019年, 三门学科(‘英语', ‘数学', ‘语文')分数按学期,学科统计最低分,最高分和平均分,统计结果按学期和学科排序 SQL:
1
2
3
4
5
6
7
|
select
school_term, subject,
count
(score),
min
(score),
max
(score),
avg
(score)
from
student_score
where
school_term
between
2000
and
2019
and
subject
in
(
'英语'
,
'数学'
,
'语文'
)
and
is_deleted = 0
group
by
school_term, subject
order
by
school_term, subject
|
1
2
3
4
5
6
7
8
9
|
@Data
public
class
ScoreStatistics {
private
int
schoolTerm;
private
String subject;
private
long
count;
private
Integer minScore;
private
Integer maxScore;
private
BigDecimal avgScore;
}
|
1
2
3
4
5
6
7
8
9
10
11
|
public
interface
StudentScoreDao
extends
IBaseDao<StudentScoreEntity> {
/**
* 统计从fromYear到endYear年间学科subjects的统计数据
*
* @param fromYear 统计年份区间开始
* @param endYear 统计年份区间结尾
* @param subjects 统计的学科列表
* @return 统计数据
*/
List<ScoreStatistics> statistics(
int
fromYear,
int
endYear, String[] subjects);
}
|
在StudentScoreDaoImpl上实现业务逻辑 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
@Repository
public
class
StudentScoreDaoImpl
extends
StudentScoreBaseDao
implements
StudentScoreDao {
@Override
public
List<ScoreStatistics> statistics(
int
fromSchoolTerm,
int
endSchoolTerm, String[] subjects) {
return
super
.listPoJos(ScoreStatistics.
class
,
super
.query()
.select.schoolTerm().subject()
.count(
"count"
)
.min.score(
"min_score"
)
.max.score(
"max_score"
)
.avg.score(
"avg_score"
)
.end()
.where.isDeleted().isFalse()
.and.schoolTerm().between(fromSchoolTerm, endSchoolTerm)
.and.subject().in(subjects)
.end()
.groupBy.schoolTerm().subject().end()
.orderBy.schoolTerm().asc().subject().asc().end()
);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
@RunWith
(SpringRunner.
class
)
@SpringBootTest
(classes = QuickStartApplication.
class
)
public
class
StudentScoreDaoImplTest {
@Autowired
private
StudentScoreDao dao;
@Test
public
void
statistics() {
List<ScoreStatistics> list = dao.statistics(
2000
,
2019
,
new
String[]{
"语文"
,
"数学"
,
"英语"
});
System.out.println(list);
}
}
|
查看控制台输出结果:
DEBUG - ==> Preparing: SELECT school_term, subject, count(*) AS count, MIN(score) AS min_score, MAX(score) AS max_score, AVG(score) AS avg_score FROM student_score WHERE is_deleted = ? AND school_term BETWEEN ? AND ? AND subject IN (?, ?, ?) GROUP BY school_term, subject ORDER BY school_term ASC, subject ASC DEBUG - ==> Parameters: false(Boolean), 2000(Integer), 2019(Integer), 语文(String), 数学(String), 英语(String) DEBUG - <== Total: 30 [ScoreStatistics(schoolTerm=2000, subject=数学, count=17, minScore=1, maxScore=93, avgScore=36.0588), ... ScoreStatistics(schoolTerm=2009, subject=语文, count=24, minScore=3, maxScore=100, avgScore=51.2500)] 。
到此这篇关于Fluent Mybatis实际开发中的优势的文章就介绍到这了,更多相关Fluent Mybatis开发内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://blog.csdn.net/qq_27933251/article/details/115378245 。
最后此篇关于Fluent Mybatis实际开发中的优势对比的文章就讲到这里了,如果你想了解更多关于Fluent Mybatis实际开发中的优势对比的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这是我的 Fluent 模型 struct Ailment: PostgreSQLModel { enum Frequency: String , Content { case regular
我正在尝试使用 Fluent Nhibernate 自动映射一个简单的继承层次结构,并且我需要为每个表使用与其类稍有不同的名称(下划线而不是 Pascal 大小写)。这似乎是一个使用约定的明显地方。我
如何为没有标识列的表指定流畅的 NHibernate 映射? 我想要这样的东西: public sealed class CustomerNewMap : ClassMap, IMap { p
使用 FluentMigrator,有没有办法找出 MigrateUp() 函数是否确实会迁移某些东西,或者它是否已经是最新的? 最佳答案 没有简单的方法可以使用公共(public) api 判断 M
我正在使用 Fluent NHibernate,我喜欢它! 我有一个小问题:启动时间大约是 10 秒,我不知道如何优化 Fluent nHibernate 为了减少这个启动时间的问题,我把它放在一个线
我在 Fluent NHIbernate 中使用 AutoPersistenceModel 来映射我的所有实体,并且一切正常:D 但是,我的几个对象有 public virtual IList Com
我有一个数据库,我正在运行多个应用程序。我喜欢通过为每个应用程序创建模式来分隔表。对于我最新的应用程序,我使用的是 FluentNHibernate。似乎我的大部分管道都是正确的,但是当我尝试查询其中
应用程序有许多扩展程序集,它们包含其类的映射。我需要为这些映射中的所有(基本、连接、多对多等)表名添加前缀。 例如 Assembly: ~/bin/Extensions/Foo.dll
您好,我很好奇 DDD 是如何使用 Fluent Nhibernate 真正实现的。例如,我有一个名为 User 的实体类和另一个名为 UserProfile 的类,就我而言,UserProfile
是否可以在 Fluent NHibernate 中映射来自多个程序集的实体? 我试过了 AutoPersistenceModel .MapEntitiesFromAssemblyOf() .AddEn
我有一个看起来像这样的基类: public abstract class MyBaseClass { public virtual DateTime UpdatedOn { get; set;
我有 Post 和 Comment 类,它们有一对多的关系,其中 Post 有一个评论列表。我如何将其映射为与 Fluent NHibernate 的单向关系,因为评论不需要知道其父 Post?目前,
我对如何查询模型对象的子对象并立即使用它感到困惑。我的Client包含数量Station child final class Client: PostgreSQLModel { var sta
目前我有一个表“ComponentAnalysis”和一个表“HistoryOfUse”,我正试图在 Fluent NHibernate 中进行映射。 一个成分分析应该只有1个使用历史,一个使用历史应
正如标题所说,我想知道我是否应该避免将 fluent nhibernate 用于生产代码,或者它是否足够成熟,可以“深入研究”? :) 最佳答案 FluentNHibernate API 尚未稳定下来
我正在尝试使用 Fluent NHibernate,我有几个问题。我发现缺少文档。 我知道 Fluent NHibernate/NHibernate 允许您自动生成数据库模式。人们通常只对测试/开发数
我正在使用 fluent-nhibernate 约定来映射我的实体: public class HasManyConvention : IHasManyConvention {
如何更改多列索引中的列顺序? IE: mapping.References(x => x.SomeReference).SetAttribute("index", "IX_index"); mappi
我需要像下面的代码一样创建一个外键: Create.ForeignKey().FromTable("TCGDocFiscalOpMedItem").ForeignColumn("IDCabecalho
我正在使用 Sharp 架构,并且在许多情况下都在实体中使用了值对象。这是一个明显的简单示例: public class Person : Entity { protected Person(
我是一名优秀的程序员,十分优秀!