-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
EasyEE-shpringboot-readme-en.md
721 lines (534 loc) · 21.2 KB
/
EasyEE-shpringboot-readme-en.md
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# EasyEE-SH(JPA)-SpringBoot Platform Development Manual
EasyEE is an open source JaveEE enterprise-class rapid development of the basic platform, provide a variety of technical options options, support Spring Boot, Hibernate, MyBatis, Struts, Shiro and other core framework.
It integrates the widely used framework of JaveEE domain and EasyUI front-end framework. It provides the back-end rights management system, security management framework and common development components based on user, role and permission scheme. Provides infrastructure and specifications for enterprise-level project development.
[EasyEE Auto](https://github.com/ushelp/EasyEE-Auto 'EasyEE Auto') automated code generator is provided.
## SH(JPA)-Spring Boot Framework
- **Spring Boot 1.5+**
- **Hibernate 5+(JPA)**
- **Shiro 2+**
- EasyCommonDAO
- EasyShiro
- EasyFilter
- EasyUI 1.4+
- EasyUIEx 2.2+
## EasyEE Auto
EasyEE Automated code generator。
[EasyEE Auto](https://github.com/ushelp/EasyEE-Auto 'EasyEE Auto')
## Framework Manual
1. Project structure
2. Quick Development Manual
3. Run with WAR or JAR
4. Other configuration instructions
## Project structure
```JS
EasySH-SpringBoot
+ src/main/java
+ cn.easyproject.easyee.sh
+ base (Base Common Package)
+ configuration (Spring Boot Configuration)
+ controller
+ BaseController.java(All Controller extends BaseController)
+ dao
+ CommonDAO.java
+ impl
+ CommonDAOSpringImpl.java
+ service
+ BaseService.java (All Service extends BaseService)
+ util
+ ... (PageBean, EasyCriteria, Encryption, Utils....)
+ sys (RBAC Package)
+ action, entity, service, util, shiro, criteria...
+ hr (Demo Module Package)
+ action, entity, service, criteria...
+ EasyEEJarApplication.java (Run as jar)
+ EasyEEWarApplication.java (Run as war)
+ src/main/resource
+ i18n
+ messages.properties (i18n)
+ messages_zh_CN.properties (i18n)
+ spring
+ spring_shiro.xml (Spring Shiro)
+ static (web static resources...)
+ doc
+ error
+ script (project module js, with WEB-INF/content)
+ main
+ sys (RBAC)
+ main.js (main.jsp)
+ login.js (login.jsp)
+ staticresources
+ easyee
+ json (easyssh json: theme, icon)
+ easyee-sh.main.js (easyssh core js)
+ jquery.cookie.js
+ easyui (EasyUI )
+ easyuiex (EasyUIEx)
+ echarts (EChars)
+ error (JSP Error Page)
+ images
+ style
+ easyee.main.css (easyssh golbal css)
+ favicon.ico
+ application.properties (Spring Boot properties)
+ banner.txt (Spring Boot Banner)
+ easyFilter.properties (EasyFilter Web request filter)
+ ehcache.xml (ehcache )
+ log4j.properties (Log4J)
+ log4j2.xml (Log4J2)
+ logback.xml (LogBack)
+ src/test/java
+ src/test/resource
+ src/main/webapp (JSP dynamic web resources)
+ META-INF
+ WEB-INF
+ content (project page)
+ dialog (EasyUI Dialog)
+ sys (RBAC)
+ hr (Demo module)
+ error
+ controllerError.jsp (Controller error)
+ notFound.jsp (404 error)
+ permissionDenied.jsp (no permission)
+ serverError.jsp (500 error)
+ jsp
+ echarts (ECharts demo)
+ VerifyCode.jsp (CAPTCHA JSP)
+ locklogin
+ admin.jsp (EasyShiro LockLogin Management)
+ main (EasyUI Core page)
+ sys (RBAC page)
+ hr (Demo Page)
+ reports
+ main.jsp (EasySSH Main Page)
+ login.jsp
```
## Quick Development Manual
1. **Create new moudle package**
cn.easyproject.easyee.sh.`yourmodule`
cn.easyproject.easyee.sh.yourmodule.`entity`
cn.easyproject.easyee.sh.yourmodule.`service`
cn.easyproject.easyee.sh.yourmodule.`controller`
cn.easyproject.easyssh.yourmodule.`criteria`
2. **Create POJO in entity package(Annotaion or XML)**
```JAVA
@Entity
@Table(name = "Dept")
public class Dept implements java.io.Serializable {
//...
}
```
3. **Create Service in service package**
- Interface, Use `@Transactional` to declare transaction
```JAVA
@Transactional
public interface DeptService {
public void save(Dept dept);
public void delete(Serializable deptno);
public void update(Dept dept);
@Transactional(readOnly=true)
public Dept get(Integer deptno);
@SuppressWarnings("rawtypes")
@Transactional(readOnly=true)
public void findByPage(PageBean pageBean, DeptCriteria deptCriteria);
@Transactional(readOnly=true)
public int findMaxPage(int rowPerPage);
@Transactional(readOnly=true)
public List<Dept> findAll();
}
```
- Implements in `service.impl`
- extends BaseService
- direct invoke commonDAO method
- use @Service
```JAVA
/**
* extends BaseService
* direct invoke commonDAO method
*
* @author easyproject.cn
* @version 1.0
*
*/
@Service("deptService")
public class DeptServiceImpl extends BaseService implements DeptService {
@Override
public void save(Dept dept) {
commonDAO.persist(dept);
}
@Override
public void delete(Serializable deptno) {
commonDAO.updateByJpql("delete from Dept where deptno=?",deptno);
}
@Override
public void update(Dept dept) {
commonDAO.merge(dept);
}
@Override
public Dept get(Integer deptno) {
return commonDAO.find(Dept.class, deptno);
}
@SuppressWarnings("rawtypes")
@Override
public void findByPage(PageBean pageBean, DeptCriteria deptCriteria) {
pageBean.setEntityName("Dept dept");
pageBean.setSelect("select dept");
// Pagination
commonDAO.findByPage(pageBean,deptCriteria);
}
@Override
public int findMaxPage(int rowPerPage) {
return commonDAO.findMaxPage("select count(*) from Dept", rowPerPage);
}
@SuppressWarnings("unchecked")
@Override
public List<Dept> findAll() {
return commonDAO.find("from Dept");
}
}
```
4. **Create a Controller**
```JAVA
/**
* Must extends BaseController
*
* BaseAction includes:
* - request, application Servlet API
* - JSON parameters
* - Init JSON data method(setJsonMap,setJsonMsgMap,setJsonPaginationMap(PageBean, Object...))
* - Get PageBean:super.getPageBean()
*
* @author easyproject.cn
* @version 1.0
*/
@RestController
@RequestMapping("Dept")
public class DeptController extends BaseController {
@Resource
private DeptService deptService;
@Resource
private EmpService empService;
/**
* forward to page
* @return
*/
@RequestMapping("page")
public ModelAndView page(ModelAndView mv){
mv.setViewName("main/hr/Dept");
return mv;
}
/**
* CRUD
* @return
*/
@RequestMapping("save")
public Map<Object,Object> save(Dept dept){
try {
deptService.save(dept);
super.setMsgKey("msg.saveSuccess");
} catch (Exception e) {
e.printStackTrace();
super.setMsgKey("msg.saveFail");
super.setStatusCode(StatusCode.ERROR); //默认为OK
}
/*
* Ajax
* {
* statusCode: 响应状态码;
* msg: 响应消息;
* callback: 执行回调函数,
* locationUrl: 跳转页面
* }
*/
// super.setJsonMsgMap();
// When save object, update row data
return super.setJsonMsgMap("rowData", dept);
// Goto last page
// int page = deptService.findMaxPage(rows);
// return super.setJsonMsgMap("rowData", dept, "page", page);
}
/**
* Pagination
* @return
*/
@SuppressWarnings("rawtypes")
@RequestMapping("list")
public Map<Object,Object> list(DeptCriteria deptCriteria){
PageBean pb = super.getPageBean(); // 获得分页对
deptService.findByPage(pb,deptCriteria);
return super.setJsonPaginationMap(pb);
}
@RequestMapping("delete")
public Map<Object,Object> delete(Dept dept){
try {
if(empService.findEmpCountByDeptno(dept.getDeptno())==0){
deptService.delete(dept.getDeptno());
}else{
super.setMsgKey("hr.DeptController.empExists");
super.setStatusCode(StatusCode.ERROR);
}
} catch (Exception e) {
e.printStackTrace();
super.setStatusCode(StatusCode.ERROR); // Default is OK
}
return super.setJsonMsgMap();
}
@RequestMapping("update")
public Map<Object,Object> update(Dept dept){
try {
deptService.update(dept);
super.setMsgKey("msg.updateSuccess");
} catch (Exception e) {
e.printStackTrace();
super.setMsgKey("msg.updateFail");
super.setStatusCode(StatusCode.ERROR); //Default is OK
}
return super.setJsonMsgMap();
}
}
```
5. **Page**
- Create folder:
- `webapp/WEB-INF/content/main/yourmodule`(EasyUI page)
- `webapp/WEB-INF/content/dialog/yourmodule`(EasyUI Dialog page)
- Develop Page
- EasyEE use `EasyUI Tabs` of `href` include page,.
> EasyUI Two Dynamic Tabs difference between dynamic loading:
>
> **-Use content (iframe frame) the introduction page:**
> content : '<iframe scrolling="auto" frameborder="0" src="'+ url + '" style="width:100%;height:100%;"></iframe>';
> Exist as a separate window, the page content independent, non-interfering with the current page
> Need to introduce independent JS and CSS resources needed
> Pop-up content is within the window
>
> **-Use href methods:**
> href : url,
> A piece of content is loaded, the introduction of the contents of the current page and merge
> Need to introduce JS and CSS resource page has introduced
> Reference page can not have a body, or the contents of the internal loads of grammar JS file execution
> Html rendering prompt resolution displays
> To prevent inter-page DOM element, naming conflicts of JS (DOM unique name should be the same prefix, JS using namespaces)
-To prevent unique prefix naming conflicts between pages DOM elements, you should use unified DOM element for each page
- In order to prevent inter-page JavaScript variable naming conflicts should be defined only operating namespace for each page, all registration functions into the namespace
- Recommended default development is structured as follows:
```JSP
<%-- 1. Page Datagrid initialization related JS --%>
<script type="text/javascript">
// To avoid naming conflicts, define a unique operating namespace for each page
// All functions registered into the namespace
var sysRole = {};
$(function() {
/*
* datagrid init
*/
// ...
/*
* datagrid CRUD
*/
/*
* datagird search
*/
});
</script>
<%-- 2. content, don't need Body --%>
<!-- ... -->
<%-- grid contextmenu --%>
<!-- ... -->
<%-- 3. Dialog Page--%>
<!-- ... -->
```
6. **And configure access permissions**
1. User Admin to Add `Menu Permission`(`/Dept/page`, click on the menu to access the action requested JSP views)
2. User Admin to Add `Operation Permission`(CRUD Permission, Show Controller Permission)
3. Assign `permissions and menu` operations for user
## Run with WAR or JAR
### Run with WAR
1. Use `pom_war.xml` to `pom.xml`
2. Uncomment the comment, Run `EasyEEWarApplication.java`
### Run with JAR
1. Use `pom_jar.xml` to `pom.xml`
2. Uncomment the comment, Run `EasyEEJarApplication.java`
## Other configuration instructions
### 1. EasySSH Ajax Response
- EasySSH Ajax Response JSON:
```JSON
{
statusCode: status code,
msg: message,
callback: callback function,
locationUrl: goto location,
//... other data
}
```
- BaseAction out JSON method:
```JAVA
// you can define JSON root data
setJsonRoot(Object);
// JSON include your Object
setJsonMap(Object...)
// JSON include your Object and EasySSH Ajax response
setJsonMsgMap(Object...)
// JSON include your Object, Pagination data and EasySSH Ajax response
setJsonPaginationMap(PageBean, Object...)
```
### 2. BaseAction
- Servlet API(request, application )
- Get PageBean:super.getPageBean()
- JSON parameter(pagination, Ajax response)
- JSON response method(`setJsonRoot`, `setJsonMap`, `setJsonMsgMap`, `setJsonPaginationMap`)
- reloadPermissions(): refreshing the user's current permission after to modify permissions
- utils
### 3. EasyCommonDAO
[EasyCommonDAO](https://github.com/ushelp/EasyCommonDAO 'EasyCommonDAO') provides a common persistence layer operation class, encapsulates a variety of daily operation methods, including pageBean and EasyCriteria-based paging and query condition processing components.
### PageBean pagination
- Example
```JAVA
PageBean pb = new PageBean();
// FROM Clause; optional
// **If use EclipseLink is required!**
pb.setSelect(" select new com.company.ssh.entity.Account(ac.accountid, ac.qxname) ");
// FROM Clause Entity Name; rquired
pb.setEntityName("Account ac");
// Page Number; optional; default is 1
pb.setPageNo(1);
// Rows per page; optional; default is 10
pb.setRowsPerPage(4);
// WHERE Clause; optional; default is ''
pb.setCondition(" and ac.accountid>2");
// Append where clause condition; optional; default is ''
// pb.addCondition(" and name='A'");
// SortName; optional; default is ''
pb.setSort("ac.accountid");
// SortOrder; optional; default is 'asc'
pb.setSortOrder("desc");
// Other sorting methods; optional; default is ''
pb.setLastSort(",time desc");
// Execute pagination quries
commonDAO.findByPage(pb);
// Pagination data
System.out.println(pb.getData());
System.out.println(pb.getPageNo());
System.out.println(pb.getRowsPerPage());
System.out.println(pb.getRowsCount());
System.out.println(pb.getPageTotal());
```
- Example2
```JAVA
// Immediate use this query
// data sql
pb.setQuery("select ac from Account ac where ac.accountid>=10 and ac.accountid<1000");
// total sql
pb.setCountSQL("select count(1) from Account ac where ac.accountid>=10 and ac.accountid<1000");
// Page Number; optional; default is 1
pb.setPageNo(1);
// Rows per page; optional; default is 10
pb.setRowsPerPage(4);
// Execute pagination quries
commonDAO.findByPage(pb);
// Pagination data...
```
#### EasyCriteria criteria queries
1. New your EasyCriteria class, must extends EasyCriteria implements Serializable
2. Write your condition by getCondition()
3. Find by EasyCriteria
- Example
```JAVA
public class SysUserCriteria extends EasyCriteria implements java.io.Serializable {
// 1. Criteria field
private String name;
private String realName;
private Integer status; // 0 is ON; 1 is OFF; 2 is REMOVED
// 2. Constructor
public SysUserCriteria() {
}
public SysUserCriteria(String name, String realName, Integer status) {
super();
this.name = name;
this.realName = realName;
this.status = status;
}
// 3. Condition genertator abstract method implements
public String getCondition() {
values.clear(); // **Must clear old values**
StringBuffer condition = new StringBuffer();
if (StringUtils.isNotNullAndEmpty(this.getName())) {
condition.append(" and name like ?");
values.add("%" + this.getName() + "%");
}
if (StringUtils.isNotNullAndEmpty(this.getRealName())) {
condition.append(" and realName like ?");
values.add("%" + this.getRealName() + "%");
}
if (StringUtils.isNotNullAndEmpty(this.getStatus())) {
condition.append(" and status=?");
values.add(this.getStatus());
}
return condition.toString();
}
// 4. Setters&Getters...
}
```
- Usage
```JAVA
PageBean pageBean = new PageBean();
pageBean.setEntityName("SysUser users");
pageBean.setSelect("select users");
// EasyCriteria
SysUserCriteria usersCriteria =new SysUserCriteria();
usersCriteria.setName("A");
usersCriteria.setStatus(0);
// Find by EasyCriteria
commonDAO.findByPage(pageBean, usersCriteria);
```
### 5. Rights Profile
- **Access Configuration**
1. Adding menu rights and operation permissions
2. The menu for the role permissions and rights are allocated
3. Assign roles to users
- **Show Controller(e.g. WEB-INF/content/jsp/module/dept.jsp)**
1. Show Permissions Configuration Permissions action in operation
2. Include `siro-tags` taglig, You will need to display the contents of the definition of control in `shiro:hasPermission` within,` name` specified must have permission to display the name of the action
```JSP
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<shiro:hasPermission name="deptDeleteShow">
<div onclick="$('#deptDataGrid').edatagrid('destroyRow')" data-options="iconCls:'icon-remove'">Delete</div>
</shiro:hasPermission>
```
3. Assign rights for users
### 6. Add-ons:
- **EasyShiro** ([API](http://easyproject.cn/easyshiro/en/index.jsp#readme "EasShiro API"))
EasyShiro based Shiro is a security extension components. Database rights management and Web URL authorization RBAC (Role Based Access Control) Web-based permission model provides universal support. EasyShiro simplifies security integration, and verification code, auto login, login is locked, an error message management, interceptors, Ajax, etc. in response to a more powerful and comprehensive feature support, only a simple configuration can be.
- **EasyFilter Jave Web Request paramtere filter** ([API](http://easyproject.cn/easyfilter/zh-cn/index.jsp#readme "EasyFilter API"))
EasyFilter is a Jave Web content filtering request replacement of a component, supports the use of properties or xml configuration file to customize the filter configuration, the user can request the following information to filter replacement:
1. Replace special characters (such as: & lt ;, & gt; special tags, scripts, etc.)
2. Illegal keyword substitution (such as: network situation does not allow China's special keywords)
3. SQL-injection filter (eg:%, *, or, delete, and so on SQL special keyword)
**In `easyFilter.xml` has predefined default alternative arrangement.**
- **EasyCommons** ([API](http://easyproject.cn/easycommons/zh-cn/index.jsp#readme "EasyCommons API"))
- EasyCommons-imageutils
Provide a picture compression, picture address extraction, image watermarking tools.
- EasyCommons-objectutils
Provided instead of Java Properties object properties file operations component.
- EasyCommons-propertiesutils
Provided (`FieldExpression`) field expression object attribute extraction based on object attribute filter, waited in vain for the object attribute is set Obejct object manipulation components.
### 7. EasyUIEx
[EasyUIEx API](http://easyproject.cn/easyuiex "EasyUIEx API") use jQuery EasyUI framework for the development of extensible plug-ins, mainly for common functions EasyUI framework encapsulates and expansion EasyUI can greatly increase the ease of use, simplify operational complexity, and provide additional functionality.
Use during project development jQuery EasyUI + EasyUIEx architecture can greatly simplify the complexity EasyUI framework uses, especially in the various aspects of CRUD data grid, he made a high degree of packaging.
In the project, a priority search EasyUIEx API functions can be done to achieve a multiplier effect.
## Demo
[Demo Online](http://www.easyproject.cn/easyee 'Demo')
Username: `demo`
Password: `111111`
![Demo](../images/easyee.png)
## End
Email:<[email protected]>
[http://www.easyproject.cn](http://www.easyproject.cn "EasyProject Home")
**Donation/捐助:**
<a href="http://www.easyproject.cn/donation">
<img alt="
支付宝/微信/QQ/云闪付/PayPal 扫码支付" src="http://www.easyproject.cn/thanks/donation.png" title="支付宝/微信/QQ/云闪付/PayPal 扫码支付" height="320" width="320"></img></a>
<div>支付宝/微信/QQ/云闪付/PayPal</div>
<br/>
我们相信,每个人的点滴贡献,都将是推动产生更多、更好免费开源产品的一大步。
**感谢慷慨捐助,以支持服务器运行和鼓励更多社区成员。**
We believe that the contribution of each bit by bit, will be driven to produce more and better free and open source products a big step.
**Thank you donation to support the server running and encourage more community members.**