這3張表的關(guān)系是模型表Model ===> 訓(xùn)練表Training ===》應(yīng)用表Application(大概的邏輯是:選擇應(yīng)用,然后訓(xùn)練,然后成為模型)
首先我們先建立實(shí)體Model(我使用的data注解不需要get set @TableField(exist = false) 注解下的屬性 是相關(guān)聯(lián)表的屬性)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package cn.com.befery.dataai.po; import java.util.Date; import org.springframework.boot.jackson.JsonComponent; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; @JsonComponent () @Data @TableName ( "ai_model" ) public class Model { @TableId (value = "model_id" , type = IdType.AUTO) private Long modelID; private Long applicationId; private Long trainingId; private String modelName; // 描述 private String modelDescribe; private String modelType; private Date createDate; private String filePath; private String fileName; private String daimension; //維度 private Long status; @TableField (exist = false ) private String applicationName; @TableField (exist = false ) private String trainingName; @TableField (exist = false ) private String order; @TableField (exist = false ) private String orderdir; // 升序或降序 } |
然后是第二個(gè)相關(guān)聯(lián)的表 應(yīng)用表application表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package cn.com.befery.dataai.po; import java.io.Serializable; import java.util.Date; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; @Data @TableName ( "ai_application" ) public class Application implements Serializable{ private static final long serialVersionUID = 1L; @TableId (value= "application_id" ,type=IdType.AUTO) private Long applicationID; private String applicationName; private String filePath; private String fileName; private Long userId; private Date createDate; private Integer status; private String dimension; //維度 @TableField (exist= false ) private String userName; //關(guān)聯(lián)用戶表的名稱字段 @TableField (exist = false ) private String order; @TableField (exist = false ) private String modelName; @TableField (exist = false ) private String trainingName; @TableField (exist = false ) private String orderdir; //升序或降序 } |
然后是相關(guān)聯(lián)的第3張表 訓(xùn)練表traning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package cn.com.befery.dataai.po; import java.io.Serializable; import java.util.Date; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; @Data @TableName ( "ai_training" ) public class Training implements Serializable { private static final long serialVersionUID = 1L; @TableId (value = "training_id" , type = IdType.AUTO) private Long trainingID; private Long serverId; //服務(wù)器ID private Long applicationId; //應(yīng)用ID private String trainingModel; //訓(xùn)練模型 private String trainingName; //訓(xùn)練名稱 private String dimensionInput; //輸入維度 private String dimensionOutput; //輸出維度 private Date createDate; private Integer status; @TableField (exist = false ) private String applicationName; @TableField (exist = false ) private String serverName; @TableField (exist = false ) private String modelName; @TableField (exist = false ) private String order; //排序字段 @TableField (exist = false ) private String orderdir; //升序或降序 } |
然后是DAO層:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
package cn.com.befery.dataai.dao; import java.util.List; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.baomidou.mybatisplus.plugins.pagination.Pagination; import cn.com.befery.dataai.po.Model; public interface ModelDao extends BaseMapper<Model> { List<Model> selectModelPage(Pagination page, @Param (value = "model" ) Model model); } |
然后是xml(sql語(yǔ)句使用了別名,別名和實(shí)體中的一致,包括之后的前后臺(tái)交互,都取一致的名字,規(guī)范避免出錯(cuò))【我之所以使用 $ 符號(hào)是因?yàn)?如果使用#號(hào)他會(huì)當(dāng)作字符串識(shí)別,他不會(huì)當(dāng)作關(guān)鍵字識(shí)別,我使用#號(hào)不行】
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<? xml version = "1.0" encoding = "UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> < mapper namespace = "cn.com.befery.dataai.dao.ModelDao" > < select id = "selectModelPage" resultType = "cn.com.befery.dataai.po.Model" > SELECT model.`model_id`, model.`model_name` as modelName, model.`status`as status, t.`training_name`as trainingName, ap.`application_name` as applicationName, model.`create_date` as createDate FROM ai_model model LEFT JOIN ai_training t ON t.`training_id` = model.`training_id` LEFT JOIN ai_application ap ON ap.`application_id` = t.`application_id` < where > 1 = 1 < if test = "model.modelName != null and model.modelName != ''" > and model.`model_name` like '%${model.modelName}%' </ if > order by ${model.order} ${model.orderdir} </ where > </ select > </ mapper > |
然后就是service:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package cn.com.befery.dataai.service; import javax.servlet.http.HttpServletRequest; import org.springframework.web.multipart.MultipartFile; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.IService; import cn.com.befery.dataai.po.Model; import cn.com.befery.dataai.vo.ResultCode; public interface ModelService extends IService<Model>{ //分頁(yè) Page<Model> selectModelPage( int pageNo, int pageSize,Model model); } |
然后就是serviceImpl:(此處將接口中的 pageNo和pageSize封裝成到 分頁(yè)輔助類(lèi) page<T>中)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
@Service @Transactional public class ModelServiceImpl extends ServiceImpl<ModelDao, Model> implements ModelService { @Autowired private ModelDao modelDao; @Override public Page<Model> selectModelPage( int pageNo, int pageSize, Model model) { // TODO Auto-generated method stub Page<Model> page = new Page<Model>(pageNo, pageSize); return page.setRecords( this .baseMapper.selectModelPage(page, model)); } } |
然后就是Controller:
簡(jiǎn)單說(shuō)一下下面的參數(shù):
1.orderNO(排序用的):是前臺(tái)傳過(guò)來(lái)的,根據(jù)orderNO(類(lèi)似下標(biāo))找到前臺(tái)定義好的數(shù)據(jù)庫(kù)字段
2.order(排序用的):根據(jù)orderNO(類(lèi)似下標(biāo))找到前臺(tái)定義好的數(shù)據(jù)庫(kù)字段
3.orderdir(排序用的:是asc 還是desc)
4.search(前臺(tái)模糊查詢使用的):前臺(tái)傳的名字,來(lái)進(jìn)行模糊查詢
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/** * @author zhangxuewei 三表查詢 * @param param * @param request * @return */ @ResponseBody @RequestMapping (value = "/modelPage" ) public ResponseData modlePage(SearchParam param, HttpServletRequest request) { logger.info( "modlePage ..........." ); String orderNO = request.getParameter( "order[0][column]" ); String order = request.getParameter( "columns[" + orderNO + "][name]" ); String orderdir = request.getParameter( "order[0][dir]" ); String search = request.getParameter( "search[value]" ); int pageNo = param.getStart() / param.getLength() + 1 ; int pageSize = param.getLength(); Model model = new Model(); model.setModelName(search); model.setOrder(order); model.setOrderdir( "asc" .equals(orderdir) ? "asc" : "desc" ); Page<Model> pageDate = modelService.selectModelPage(pageNo, pageSize, model); return responseData(param.getDraw(), pageDate); } |
這個(gè)是分頁(yè)返回公共類(lèi)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package cn.com.befery.dataai.controller; import org.springframework.stereotype.Controller; import com.baomidou.mybatisplus.plugins.Page; import cn.com.befery.dataai.vo.ResponseData; @Controller public class BaseController { /** * * @param draw 重構(gòu)次數(shù) * @param page 分頁(yè)數(shù)據(jù) * @return */ public ResponseData responseData(String draw,Page<?> page){ ResponseData res = new ResponseData(); res.setData(page.getRecords()); res.setDraw(draw); res.setRecordsFiltered(( int )page.getTotal()); res.setRecordsTotal(( int )page.getTotal()); return res; } } |
這個(gè)是ResponseDate實(shí)體類(lèi)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package cn.com.befery.dataai.vo; import java.util.List; //@JsonInclude(Include.NON_NULL) public class ResponseData { /** * */ // private static final long serialVersionUID = 1L; private String draw; private int recordsTotal; private int recordsFiltered; @SuppressWarnings ( "rawtypes" ) private List data; } |
這是前端的html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
<!DOCTYPE HTML> < html > < head > < meta charset = "utf-8" > < meta name = "renderer" content = "webkit|ie-comp|ie-stand" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" > < meta name = "viewport" content = "width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> < meta http-equiv = "Cache-Control" content = "no-siteapp" /> <!--[if lt IE 9]> <script type="text/javascript" src="lib/html5.js"></script> <script type="text/javascript" src="lib/respond.min.js"></script> <script type="text/javascript" src="lib/PIE_IE678.js"></script> <![endif]--> < link rel = "stylesheet" type = "text/css" href = "../static/h-ui/css/H-ui.min.css" rel = "external nofollow" /> < link rel = "stylesheet" type = "text/css" href = "../static/h-ui/css/H-ui.admin.css" rel = "external nofollow" /> < link rel = "stylesheet" type = "text/css" href = "../static/libs/Hui-iconfont/1.0.7/iconfont.css" rel = "external nofollow" /> < link rel = "stylesheet" type = "text/css" href = "../static/libs/icheck/icheck.css" rel = "external nofollow" /> < link rel = "stylesheet" type = "text/css" href = "../static/h-ui/skin/default/skin.css" rel = "external nofollow" id = "skin" /> < link rel = "stylesheet" type = "text/css" href = "../static/h-ui/css/style.css" rel = "external nofollow" /> <!--[if IE 6]> <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script> <script>DD_belatedPNG.fix('*');</script> <![endif]--> < title >應(yīng)用列表</ title > < style type = "text/css" > .dataTables_wrapper .dataTables_length { float: left; padding-bottom: 0px; padding-top: 10px; padding-left: 20px; } .table tbody tr td:FIRST-CHILD { text-align: center; } .table tbody tr td { text-align: center; } .dataTables_wrapper .dataTables_filter { padding-bottom: 10px; } .mt-20 { margin-top: 10px; } .page-container { padding: 20px; padding-top: 0px; } .form-horizontal .form-label { text-align: left; width: 140px; padding-right: 0px; } </ style > </ head > < body > < nav class = "breadcrumb" > < i class = "Hui-iconfont" ></ i > 首頁(yè) < span class = "c-gray en" >></ span > 模型和測(cè)試管理 < span class = "c-gray en" >></ span > 模型列表 < a class = "btn btn-success radius r" id = "refresh" style = "line-height: 1.6em; margin-top: 3px" href = "javascript:location.replace(location.href);" rel = "external nofollow" title = "刷新" >< i class = "Hui-iconfont" ></ i ></ a > </ nav > < div class = "page-container" > <!-- <div class="text-c"> 日期范圍: <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}',minDate:'#F{$dp.$D(\'logmax\',{M:-3})}'})" id="logmin" class="input-text Wdate" style="width:120px;"> - <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'logmin\',{M:3})||\'%y-%M-%d\'}',minDate:'#F{$dp.$D(\'logmin\')}'})" id="logmax" class="input-text Wdate" style="width:120px;"> <input type="text" name="" id="search" placeholder=" 門(mén)店名稱" style="width:250px" class="input-text"> <button name="" id="search" class="btn btn-success" type="submit" onclick="search()"><i class="Hui-iconfont"></i> 搜賬戶</button> </div> --> <!-- <div style="display: <#if(modelServer)??>${modelServer" class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" id="addApp" onclick="modelServerServer_add('創(chuàng)建模型服務(wù)','/pages/modelServer-add.html')" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><i class="Hui-iconfont"></i> 創(chuàng)建模型服務(wù)</a><a id="datarefresh" onclick="data_refresh()"></a><input id="hiddentext" type="text" hidden="true" /> <input id="msgsecret" type="text" hidden="true" /> </div> --> < div style="display: <#if (model)??>${model}<#else></#if>" class="cl pd-5 bg-1 bk-gray mt-20"> < span class = "l" > < a class = "btn btn-primary radius" id = "addApp" onclick = "model_testing('測(cè)試模型','/pages/model-testing.html')" href = "javascript:;" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" >< i class = "Hui-iconfont" ></ i > 測(cè)試模型</ a >< a id = "datarefresh" onclick = "data_refresh()" ></ a >< input id = "hiddentext" type = "text" hidden = "true" /> < input id = "msgsecret" type = "text" hidden = "true" /></ div > < div class = "mt-20" > < table class = "table table-border table-bordered table-bg table-hover table-sort " width = 100 %> < thead > < tr class = "text-c" > <!-- <th width="40"><input id = "checkAll" name="checkAll" type="checkbox" value=""></th> --> < th width = "80" >序號(hào)</ th > < th width = "80" >模型服務(wù)名稱</ th > < th width = "100" >訓(xùn)練名稱</ th > < th width = "100" >應(yīng)用名稱</ th > < th width = "100" >創(chuàng)建時(shí)間</ th > < th width = "80" >操作</ th > </ tr > </ thead > < tbody > </ tbody > </ table > </ div > </ div > < div id = "ajaxModal" class = "modal hide fade" tabindex = "-1" > < article class = "page-container" > < form action = "" method = "post" class = "form form-horizontal" id = "form-modelServer-add" > < div class = "row cl" > < label class = "form-label col-xs-3 col-sm-3" >< span class = "c-red" >*</ span >App名稱:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" class = "input-text" value = "" placeholder = "" id = "appName" name = "appName" > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-3 col-sm-3" >< span class = "c-red" >*</ span >圖片地址:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" class = "input-text" value = "" placeholder = "" id = "adminMobile" name = "adminMobile" > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-3 col-sm-3" >< span class = "c-red" >*</ span >Domain(SaaS):</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" class = "input-text" value = "" placeholder = "" id = "payCallBackURL" name = "payCallBackURL" > </ div > </ div > < div class = "row cl" > < div class = "col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3" style = "margin-left: 130px; width: 100px;" > < button class = "btn btn-primary radius" value = "" > 提交 </ button > </ div > <!-- <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3" style="float: right; width: 250px;margin-left: 0px;"> <input class="btn btn-primary radius" style="width: 80px;" onclick="javascript:;" value=" 取消 "> </div> --> </ div > </ form > </ article > </ div > < script type = "text/javascript" src = "../static/libs/jquery/1.9.1/jquery.min.js" ></ script > < script type = "text/javascript" src = "../static/libs/layer/2.1/layer.js" ></ script > < script type = "text/javascript" src = "../static/libs/My97DatePicker/WdatePicker.js" ></ script > < script type = "text/javascript" src = "../static/libs/datatables/1.10.0/jquery.dataTables.min.js" ></ script > < script type = "text/javascript" src = "../static/h-ui/js/H-ui.js" ></ script > < script type = "text/javascript" src = "../static/h-ui/js/H-ui.admin.js" ></ script > <!-- <script type="text/javascript" src="js/modelServer.js"></script> --> < script type = "text/javascript" > var table = $('.table-sort') .DataTable( { "processing" : true, "serverSide" : true, // "searching":true, 'language' : { "search" : "按名稱檢索:", "sProcessing" : "< div style = 'position:absolute;margin-left:42%;margin-top:15%' >< img src = 'static/h-ui/images/loading_072.gif' />數(shù)據(jù)加載中...</ div >", }, "sDom" : '<"top"f<"clear">>rt<"bottom"ilp><"clear">', "order" : [ [ 0, "asc" ] ], "ajax" : { "url" : "/model/modelPage", /* "data": function ( d ) { //添加額外的參數(shù)傳給服務(wù)器 d.extra_search = "canshu1"; d.extra_search1 = "canshu11"; }, */ }, "columnDefs" : [ { orderable : false,//禁用排序 targets : [ 4 ] } ], "columns" : [ /*{"sTitle": "< input type = 'checkbox' ></ input >","mDataProp": null, "sWidth": "20px", "sDefaultContent": "< input type = 'checkbox' ></ input >", "bSortable": false,"sClass": "text-center",}, */ { "data" : "modelID", "name" : "model_id", "class" : "modelID" }, { "data" : "modelName", "name" : "model_name", "class" : "modelName" }, { "data" : "trainingName", "name" : "training_name", "class" : "trainingName" }, { "data" : "applicationName", "name" : "application_name", "class" : "applicationName" }, { "data" : function(e) { if (e.createDate != null && e.createDate != "null") { return e.createDate; } return ""; }, "name" : "create_date", "class" : "createDate" }, { "data" : function(e) { if (e.status == '0') { if (e.isTrained == '0') { return '< a style="display: <#if (modelServer_delete)??>${modelServer_delete}<#else></#if>" id="codetool">
到此這篇關(guān)于MyBatis-Plus多表聯(lián)合查詢并且分頁(yè)(3表聯(lián)合)的文章就介紹到這了,更多相關(guān)MyBatis-Plus多表聯(lián)合查詢內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家! 原文鏈接:https://blog.csdn.net/Mr_ZhangAdd/article/details/84248479 延伸 · 閱讀
精彩推薦
|