二次开发.docx
《二次开发.docx》由会员分享,可在线阅读,更多相关《二次开发.docx(14页珍藏版)》请在冰豆网上搜索。
二次开发
Jspxcms无侵入式插件开发(二次开发)教程之一:
概述
Jspxcms支持无侵入式插件和二次开发,无需修改系统原有代码,即可无缝整合Entity、Service、Controller、功能菜单、权限、标签、国际化等功能。
系统中“插件--简历管理”就是以这种方式实现的,下面就以“简历管理”讲解Jspxcms插件和二次开发的方法。
本帖隐藏的内容需要回复才可以浏览
配置文件位置:
/WEB-INF/conf/plugin。
所有的配置文件都必须在这个目录,在该目录下的配置文件会自动加载。
在该目录下新建自己的文件夹,可以是任何名字,如:
abc、novel等,本例为plug。
即/WEB-INF/conf/plugin/plug
配置文件说明
application.properties:
功能菜单、权限、国际化、Entity都与这个文件相关。
context-dao.xml:
Dao的加载。
context-service.xml:
Service的加载。
controller-back.xml:
后台Controller的加载。
controller-fore.xml:
前台Controller的加载。
context-directive.xml:
标签的加载。
其他与插件开发相关的文件目录
/WEB-INF/messages/plugin/plug:
后台国际化文件位置
/WEB-INF/messages/plugin/plugfore:
前台国际化文件位置
/WEB-INF/views/plug:
后台jsp文件位置
/files/1/bluewise/plug_resume.html:
插件的前台模版
插件源代码包名:
com.jspxcms.plug
Jspxcms无侵入式插件开发(二次开发)教程之二:
菜单与权限
本帖隐藏的内容需要回复才可以浏览
菜单和权限配置文件:
/WEB-INF/conf/plugin/plug/application.properties
一级菜单配置(分号为分割符)
1.menu.650=navigation.plug;nav.do?
menuId=650;nav_plug
复制代码
650:
是后台导航一级菜单的编号,编号大小决定菜单的前后位置。
其值可以根据需要调整,如330、970,但不要与系统菜单或其他插件菜单重复。
系统菜单通常为menu.100,menu.200,menu.600等,系统菜单定义文件在/WEB-INF/conf/application.properties
navigation.plug:
菜单名称。
这里使用了国际化,也可以直接用中文,比如“我的插件”。
nav.do?
menuId=650:
菜单链接地址。
其中650需与前面的值一样。
nav_plug:
权限值。
其中plug通常与配置文件目录名称一样。
如目录为abc,则应为nav_abc。
也可不一样,但不能与其他一级菜单权限名称一样。
二级菜单配置(分号为分割符)
1.menu.650.100=resume.management;plug/resume/list.do;plug:
resume:
list;create@plug:
resume:
create;copy@plug:
resume:
copy;edit@plug:
resume:
edit;save@plug:
resume:
save;update@plug:
resume:
update;delete@plug:
resume:
delete
复制代码
650:
二级菜单所属的一级菜单编号。
100:
二级菜单编号。
其值的意义和一级菜单编号一样,用于确定二级菜单的前后位置。
resume.management:
二级菜单名称。
可以直接用中文,如“小说管理”。
plug/resume/list.do:
功能菜单的链接地址。
需与Controller中的地址对应,否则会找不到页面。
plug:
resume:
list:
功能菜单的权限。
需与Controller中list方法的权限对应,否则会报没有权限。
create@plug:
resume:
create:
新增按钮的权限值。
其中create是国际化,可以用直接用中文,如“新增@plug:
resume:
create”。
其中plug:
resume:
create是该按钮的权限值,需与Controller中对应的create方法权限值一致。
copy@plug:
resume:
copy:
意义和上面一样,后面的以此类推。
com.jspxcms.plug.web.back.ResumeController代码片段
1.packagecom.jspxcms.plug.web.back;
2.@Controller
3.@RequestMapping("/plug/resume")
4.publicclassResumeController{
5.?
?
?
?
@RequiresPermissions("plug:
resume:
list")
6.?
?
?
?
@RequestMapping("list.do")
7.?
?
?
?
publicStringlist(......){
8.?
?
?
?
?
?
?
?
......
9.?
?
?
?
}
10.?
?
?
?
@RequiresPermissions("plug:
resume:
create")
11.?
?
?
?
@RequestMapping("create.do")
12.?
?
?
?
publicStringcreate(......){
13.?
?
?
?
?
?
?
?
......
14.?
?
?
?
}
15.?
?
?
?
......
16.}
Jspxcms无侵入式插件开发(二次开发)教程之三:
Entity
本帖隐藏的内容需要回复才可以浏览
实体类Entity配置文件:
/WEB-INF/conf/plugin/plug/application.properties
1.entityManagerFactory.packagesToScan.plug=com.jspxcms.plug.domain
复制代码
plug:
通常与配置文件所在目录一样,也可不一样,但不能与其他相关配置同名。
com.jspxcms.plug.domain:
Entity所在包名。
不使用主键自增策略,将主键放到数据库中的一个表里。
1.createtableplug_resume
2.(
3.?
?
f_resume_id?
?
?
?
?
?
intnotnull,
4.?
?
f_site_id?
?
?
?
?
?
?
?
intnotnull,
5.?
?
f_name?
?
?
?
?
?
?
?
?
?
varchar(100)notnullcomment'姓名',
6.?
?
f_post?
?
?
?
?
?
?
?
?
?
varchar(100)notnullcomment'应聘职位',
7.?
?
f_creation_date?
?
?
?
datetimenotnullcomment'投递日期',
8.?
?
f_gender?
?
?
?
?
?
?
?
char
(1)notnulldefault'M'comment'性别',
9.?
?
f_birth_date?
?
?
?
?
?
datetimecomment'出生日期',
10.?
?
f_mobile?
?
?
?
?
?
?
?
varchar(100)comment'手机',
11.?
?
f_email?
?
?
?
?
?
?
?
?
?
varchar(100)comment'邮箱',
12.?
?
f_expected_salary?
?
intcomment'期望薪水',
13.?
?
f_education_experiencelongtextcomment'教育经历',
14.?
?
f_work_experience?
?
longtextcomment'工作经历',
15.?
?
f_remark?
?
?
?
?
?
?
?
longtextcomment'备注',
16.?
?
primarykey(f_resume_id)
17.)
18.engine=innodb;
19.altertableplug_resumecomment'简历表';
20.altertableplug_resumeaddconstraintfk_plug_resume_siteforeignkey(f_site_id)
21.?
?
?
?
referencescms_site(f_site_id)ondeleterestrictonupdaterestrict;
复制代码
1.@Entity
2.@Table(name="plug_resume")
3.publicclassResumeimplementsjava.io.Serializable{
4.?
?
?
?
privateIntegerid;
5.?
?
?
?
……
6.?
?
?
?
@Id
7.?
?
?
?
@Column(name="f_resume_id",unique=true,nullable=false)
8.?
?
?
?
@TableGenerator(name="tg_plug_resume",pkColumnValue="plug_resume",table="t_id_table",pkColumnName="f_table",valueColumnName="f_id_value",initialValue=1,allocationSize=1)
9.?
?
?
?
@GeneratedValue(strategy=GenerationType.TABLE,generator="tg_plug_resume")
10.?
?
?
?
publicIntegergetId(){
11.?
?
?
?
?
?
?
?
returnthis.id;
12.?
?
?
?
}
13.?
?
?
?
publicvoidsetId(Integerid){
14.?
?
?
?
?
?
?
?
this.id=id;
15.?
?
?
?
}
16.?
?
?
?
……
17.}
复制代码
需注意以下三个值,其中plug_resume为表名:
1.name="tg_plug_resume",pkColumnValue="plug_resume"
2.generator="tg_plug_resume"
Jspxcms无侵入式插件开发(二次开发)教程之四:
Dao
本帖隐藏的内容需要回复才可以浏览
Dao配置文件:
/WEB-INF/conf/plugin/plug/context-dao.xml
1.repositoriesbase-package="com.jspxcms.plug.repository"?
2.?
?
transaction-manager-ref="transactionManager"?
3.?
?
entity-manager-factory-ref="entityManagerFactory"?
4.?
?
factory-class="mon.orm.MyJpaRepositoryFactoryBean"?
5.?
?
repository-impl-postfix="Impl">
6.
repositories>
复制代码
其中com.jspxcms.plug.repository为dao接口所在包。
Dao使用了SpringDataJPA技术。
SpringDataJPA官网:
http:
//projects.spring.io/spring-data-jpa/
1.packagecom.jspxcms.plug.repository;
2.publicinterfaceResumeDaoextendsRepository,ResumeDaoPlus{
3.?
?
?
?
publicPagefindAll(Specificationspec,Pageablepageable);
4.?
?
?
?
publicListfindAll(Specificationspec,Limitablelimitable);
5.?
?
?
?
publicResumefindOne(Integerid);
6.?
?
?
?
publicResumesave(Resumebean);
7.?
?
?
?
publicvoiddelete(Resumebean);
8.}
复制代码
ResumeDao接口中的方法不用实现。
以下接口中的方法均可放到ResumeDao,且无需实现:
1.org.springframework.data.repository.CrudRepository
2.org.springframework.data.repository.PagingAndSortingRepository
3.org.springframework.data.jpa.repository.JpaRepository
4.mon.orm.MyJpaRepository
复制代码
需要实现的dao方法,放到ResumeDaoPlus接口中。
1.packagecom.jspxcms.plug.repository;
2.publicinterfaceResumeDaoPlus{
3.?
?
?
?
publicListgetList(Integer[]siteId,Limitablelimitable);
4.}
复制代码
1.packagecom.jspxcms.plug.repository.impl;
2.publicclassResumeDaoImplimplementsResumeDaoPlus{
3.?
?
?
?
@SuppressWarnings("unchecked")
4.?
?
?
?
publicListgetList(Integer[]siteId,Limitablelimitable){
5.?
?
?
?
?
?
?
?
JpqlBuilderjpql=newJpqlBuilder();
6.?
?
?
?
?
?
?
?
jpql.append("fromResumebeanwhere1=1");
7.?
?
?
?
?
?
?
?
if(ArrayUtils.isNotEmpty(siteId)){
8.?
?
?
?
?
?
?
?
?
?
?
?
jpql.append("andbean.site.idin(:
siteId)");
9.?
?
?
?
?
?
?
?
?
?
?
?
jpql.setParameter("siteId",Arrays.asList(siteId));
10.?
?
?
?
?
?
?
?
}
11.?
?
?
?
?
?
?
?
returnjpql.list(em,limitable);
12.?
?
?
?
}
13.?
?
?
?
privateEntityManagerem;
14.?
?
?
?
@PersistenceContext
15.?
?
?
?
publicvoidsetEm(EntityManagerem){
16.?
?
?
?
?
?
?
?
this.em=em;
17.?
?
?
?
}
18.}
复制代码
其中JpqlBuilder用于拼装jqpl语句、设置参数,并可处理分页问题。
mon.orm.JpqlBuilder
Jspxcms无侵入式插件开发(二次开发)教程之五:
Service
本帖隐藏的内容需要回复才可以浏览
Service配置文件:
/WEB-INF/conf/plugin/plug/context-service.xml
1.component-scanbase-package="com.jspxcms.plug.service.impl">
2.exclude-filtertype="annotation"?
3.expression="org.springframework.stereotype.Controller"/>
4.
component-scan>
复制代码
其中com.jspxcms.plug.service.impl为Service的实现类所在包。
1.packagecom.jspxcms.plug.service.impl;
2.@Service
3.@Transactional(readOnly=true)
4.publicclassResumeServiceImplimplementsResumeService{
5.?
?
?
?
publicPagefindAll(IntegersiteId,Mapparams,
6.?
?
?
?
?
?
?
?
?
?
?
?
Pageablepageable){
7.?
?
?
?
?
?
?
?
returndao.findAll(spec(siteId,params),pageable);
8.?
?
?
?
}
9.?
?
?
?
publicRowSidefindSide(IntegersiteId,
10.?
?
?
?
?
?
?
?
?
?
?
?
Mapparams,Resumebean,Integerposition,
11.?
?
?
?
?
?
?
?
?
?
?
?
Sortsort){
12.?
?
?
?
?
?
?
?
if(position==null){
13.?
?
?
?
?
?
?
?
?
?
?
?
returnnewRowSide();
14.?
?
?
?
?
?
?
?
}
15.?
?
?
?
?
?
?
?
Limitablelimit=RowSide.limitable(position,sort);
16.?
?
?
?
?
?
?
?
Listlist=dao.findAll(spec(siteId,params),limit);
17.?
?
?
?
?
?
?
?
returnRowSide.create(list,bean);
18.?
?
?
?
}
19.?
?
?
?
privateSpecificationspec(finalIntegersiteId,
20.?
?
?
?
?
?
?
?
?
?
?
?
Mapparams){
21.?
?
?
?
?
?
?
?
Collectionfilters=SearchFilter.parse(params).values();
22.?
?
?
?
?
?
?
?
finalSpecificationfsp=SearchFilter.spec(filters,
23.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
Resume.class);
24.?
?
?
?
?
?
?
?
Specificationsp=newSpecification(){
25.?
?
?
?
?
?
?
?
?
?
?
?
publicPredicatetoPredicate(Rootroot,
26.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
CriteriaQuery
>query,CriteriaBuildercb){
27.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
Predicatepred=fsp.toPredicate(root,query,cb);
28.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
if(siteId!
=null){
29.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
pred=cb.and(pred,cb.equal(root.get("site")
30.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
.get("id"),siteId));
31.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
}
32.?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
returnpred;
33.?
?
?
?
?
?
?
?
?
?
?
?
}
34.?
?
?
?
?
?
?
?
};
35.?
?
?
?
?
?
?
?
returnsp;
36.?
?
?
?
}
37.?
?
?
?
privateResumeDaodao;
38.?
?
?
?
@Autowired
39.?
?
?
?
publicvoidsetDao(ResumeDaodao){
40.?
?
?
?
?
?
?
?
this.dao=dao;
41.?
?
?
?
}
42.?
?
?
?
......
43.}
复制代码
该类使用到JPA的Specification查询方式。
可实现后台列表点击表头,按任意列排序;列表页按任意字段查询;编辑页面上一条、下一条功能。
Jspxcms无侵入式插件开发(二次开发)教程之六:
Controller
本帖隐藏的内容需要回复才可以浏览
Controller后台配置文件:
/WEB-INF/conf/plugin/plug/controller-back.xml
1.component-scanbase-package="com.jspxcms.plug.web.back"use-default-filters="false"