In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the Jspxcms non-invasive secondary development method is what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this Jspxcms non-invasive secondary development method is what the article will have a harvest, let's take a look at it.
Chapter 1 summarizes that as a general website content management system, it can only meet most of the requirements as much as possible, but it is difficult to meet all the requirements, so the secondary development of the system is needed. For some public secondary development programs can be made into plug-ins, provided to other developers or customers to use.
1.1 profile 1.1.1 profile directory / WEB-INF/classes/conf/plugin
The core of secondary development is the configuration file, which integrates different modules and plug-ins together. All configuration files must be in this directory, and the configuration files in that directory will be loaded automatically.
Create your own folder under this directory, which can be any name, such as abc, novel, etc. This example is plug. That is / WEB-INF/classes/conf/plugin/plug.
1.1.2 profile introduction
Application.properties: function menus, permissions, internationalization, and Entity are all related to this file.
Loading of context-dao.xml:Dao.
Loading of context-service.xml:Service.
Controller-back.xml: loading of background Controller.
Controller-fore.xml: loading of foreground Controller.
Context-directive.xml: loading of tags.
1.2 Source code package name source code can be placed under any package, as long as it corresponds to the settings in the configuration file.
This example is: com.jspxcms.plug.
1.3 background JSP Files the root of the background JSP files is: / WEB-INF/views.
The detailed path depends on the address returned by Controller. If plug/resume/resume_list is returned, the corresponding JSP file is: / WEB-INF/views/plug/resume/resume_list.jsp.
The directory where the background JSP of this example resides: / WEB-INF/views/plug/resume
1.4 foreground template file foreground template uses freemarker technology, and the template root directory is: / template/1/default.
Where 1 is the site ID. Default is the template theme, and the background "system-website Settings-basic Settings" can modify this setting (provided there are multiple folders in the / template/1 directory).
The foreground template of this example is: / template/1/default/plug_resume.html. The address depends on the Controller return address.
1.5 international files edit and view international files, please install the Properties Editor plug-in for Eclipse. Otherwise, you can't see Chinese, you can only see codes like\ u5217\ u8868; if you enter Chinese directly when editing, there will be garbled codes.
The root directory of the internationalization file is: / WEB-INF/messages.
The internationalization path for this example is: / WEB-INF/messages/plugin.
Chapter 2 menus and permissions menus and permissions are the core parts of plug-in (secondary) development and the most difficult to integrate seamlessly. Most systems save menu information to the database, which brings some difficulties to upgrade and maintenance.
The menu and permission information of Jspxcms are stored in the configuration, which is convenient to manage, maintain and upgrade; as long as it is set in a configuration file, the menu, permissions, empowerment and other problems of the system can be seamlessly integrated without the need to modify the code and page.
When developing, you can add the new function menu to any location under any first-level menu according to your needs, or you can add your own first-level menu, and the new first-level menu can also be placed in any location you want.
Menu introduction Jspxcms system menu is divided into two levels.
First-level menu:
Secondary menu:
2.2 the profile profile is: application.properties
The full path in this example: / WEB-INF/classes/conf/plugin/plug/application.properties
Configuration related to menus and permissions (semicolons are separators):
Menu.650=navigation.plug;nav.do?menuId=650;nav_plug
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
Menu.650.200=dbBackup.management;plug/db_backup/list.do;plug:db_backup:list;dbBackup.backup@plug:db_backup:backup;dbBackup.restore@plug:db_backup:restore;delete@plug:workflow_group:delete
2.2.1 the first-level menu configuration is divided into three parts: menu location and name, menu link address, and right value.
Menu location and name
Menu.650=navigation.plug
650: it is the number of the first-level menu in the background navigation, and the number size determines the position of the menu before and after. The value can be adjusted as needed, such as 330, 970, but do not repeat it with the system menu or other plug-in menus. The system menu is usually menu.100, menu.200, menu.600, etc., and the system menu definition file is in / WEB-INF/classes/conf/application-menu.properties.
Navigation.plug: menu name. International code is used here, or you can use Chinese directly, such as "menu.650= my plug-in". (if you write Chinese directly in the properties file, you need to install the Properties Editor plug-in, otherwise there will be garbled codes)
Menu link address
Nav.do?menuId=650
Where 650 needs to be the same as the value of menu.650.
Permission value
Nav_plug
Where plug is usually the same as the profile directory name. If the directory is abc, it should be nav_abc. It can also be different, but it cannot be the same as other first-level menu permission names.
2.2.2 the secondary menu configuration is divided into four parts: menu location and name, menu link address, menu permission value, function name and right value.
Menu location and name
Menu.650.100=resume.management
650: the first-level menu number to which the secondary menu belongs.
100: secondary menu number. The meaning of the value is the same as the first-level menu number, which is used to determine the position before and after the second-level menu.
Resume.management: secondary menu name. Can be directly used in Chinese, such as "novel management".
Menu link address
Plug/resume/list.do
It needs to correspond to the address in Controller, otherwise the page will not be found.
Menu permission value
Plug:resume:list
It must correspond to the permission of the list method in Controller, otherwise no permission will be reported.
Function name and permission value
Create@plug:resume:create;copy@plug:resume:copy;edit@plug:resume:edit;save@plug:resume:save;update@plug:resume:update;delete@plug:resume:delete
Create@plug:resume:create: add the weight limit of the button. Create is an international code, which can be used directly in Chinese, such as "add @ plug:resume:create". Where plug:resume:create is the right limit of the button, which needs to be consistent with the corresponding permission value of the create method in Controller.
Edit@plug:resume:edit: the meaning is the same as above, and so on.
2.2.3 after the menu configuration and rights management have been set up in accordance with the above steps, the rights management section will read the configuration file without modifying the rights management page and code.
Chapter 3 ControllerController is the control part of MVC, the main function is to receive the request submitted by the client, then call the function of Service and get data, and finally return to View (view, that is, JSP or freemarker page).
In Jspxcms, Controller is divided into foreground and background. The foreground is the page browsed by ordinary users, using freemarker as the view, usually does not need to log in, such as the website home page, column page, special page, search page, etc.; the background is generally for the management function, using JSP as the view, the administrator is required to log in to the background in order to access.
Configuration file 3.1.1 background configuration file / WEB-INF/classes/conf/plugin/plug/controller-back.xml.
Com.jspxcms.plug.web.back is the package where the background Controller resides, and all the Controller under this package will be scanned by spring.
3.1.2 foreground profile / WEB-INF/classes/conf/plugin/plug/controller-fore.xml.
Com.jspxcms.plug.web.fore is the package where the foreground Controller is located, and the Controller under this package will be scanned by spring.
3.2 background Controller class
Package com.jspxcms.plug.web.back
@ Controller
@ RequestMapping ("/ plug/resume")
Public class ResumeController {
@ RequiresPermissions ("plug:resume:list")
@ RequestMapping ("list.do")
Public String list (
@ PageableDefaults (sort = "id", sortDir = Direction.DESC) Pageable pageable
HttpServletRequest request, org.springframework.ui.Model modelMap) {
Integer siteId = Context.getCurrentSiteId (request)
Map params = Servlets.getParameterValuesMap (request
Constants.SEARCH_PREFIX)
Page pagedList = service.findAll (siteId, params, pageable)
ModelMap.addAttribute ("pagedList", pagedList)
Return "plug/resume/resume_list"
}
@ RequiresPermissions ("plug:resume:create")
@ RequestMapping ("create.do")
Public String create (Integer id, org.springframework.ui.Model modelMap) {
If (id! = null) {
Resume bean = service.get (id)
ModelMap.addAttribute ("bean", bean)
}
ModelMap.addAttribute (OPRT, CREATE)
Return "plug/resume/resume_form"
}
@ Autowired
Private ResumeService service
}
Where RequestMapping is the access address and RequiresPermissions is the permission code, which should be consistent with the menu permission configuration in application.properties.
3.3 foreground Controller class
Package com.jspxcms.plug.web.fore
@ Controller
Public class ResumeController {
Public static final String TEMPLATE = "plug_resume.html"
@ RequestMapping (value = "/ resume.jspx")
Public String resumeForm (Integer page, HttpServletRequest request
Org.springframework.ui.Model modelMap) {
Site site = Context.getCurrentSite (request)
Map data = modelMap.asMap ()
ForeContext.setData (data, request)
ForeContext.setPage (data, page)
Return site.getTemplate (TEMPLATE)
}
@ RequestMapping (value = "/ resume.jspx", method = RequestMethod.POST)
Public String resumeSubmit (@ Valid Resume bean, HttpServletRequest request)
HttpServletResponse response, org.springframework.ui.Model modelMap) {
Response resp = new Response (request, response, modelMap)
Site site = Context.getCurrentSite (request)
Service.save (bean, site.getId ())
Return resp.post ()
}
@ Autowired
Private ResumeService service
}
Chapter 4 Entity4.1 configuration File / WEB-INF/classes/conf/plugin/plug/application.properties
EntityManagerFactory.packagesToScan.plug=com.jspxcms.plug.domain
Plug: usually the same as the directory where the configuration file is located, but not with the same name as other related configurations.
The name of the package in which the com.jspxcms.plug.domain:Entity is located.
4.2 Database tables do not use the primary key self-increment strategy and place the primary key in a table in the database.
Create table plug_resume
(
F_resume_id int not null
F_site_id int not null
F_name varchar (100) not null comment 'name'
F_post varchar (100) not null comment 'apply for position'
F_creation_date datetime not null comment 'delivery date'
F_gender char (1) not null default'M'comment 'gender'
F_birth_date datetime comment 'date of birth'
F_mobile varchar comment 'Mobile phone'
F_email varchar (100) comment 'mailbox'
F_expected_salary int comment 'expected salary'
F_education_experience longtext comment 'educational experience'
F_work_experience longtext comment 'work experience'
F_remark longtext comment 'remarks'
Primary key (f_resume_id)
)
Engine = innodb
Alter table plug_resume comment 'resume'
Alter table plug_resume add constraint fk_plug_resume_site foreign key (f_site_id)
References cms_site (f_site_id) on delete restrict on update restrict
4.3 entity classes should pay attention to the following three values, where plug_resume is the table name:
Name = "tg_plug_resume", pkColumnValue = "plug_resume"
Generator = "tg_plug_resume"
@ Entity
@ Table (name = "plug_resume")
Public class Resume implements java.io.Serializable {
Private Integer id
……
@ Id
@ Column (name = "f_resume_id", unique = true, nullable = false)
@ TableGenerator (name = "tg_plug_resume", pkColumnValue = "plug_resume", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
@ GeneratedValue (strategy = GenerationType.TABLE, generator = "tg_plug_resume")
Public Integer getId () {
Return this.id
}
Public void setId (Integer id) {
This.id = id
}
……
}
Chapter 5 DAO5.1 configuration File / WEB-INF/classes/conf/plugin/plug/context-dao.xml
Where com.jspxcms.plug.repository is the package where the dao API resides.
The 5.2DAO class Dao uses SpringDataJPA technology.
SpringDataJPA official website: http://projects.spring.io/spring-data-jpa/
Package com.jspxcms.plug.repository
Public interface ResumeDao extends Repository, ResumeDaoPlus {
Public Page findAll (Specification spec, Pageable pageable)
Public List findAll (Specification spec, Limitable limitable)
Public Resume findOne (Integer id)
Public Resume save (Resume bean)
Public void delete (Resume bean)
}
Methods in the ResumeDao interface do not need to be implemented. The methods in the following interfaces can be placed in ResumeDao and do not need to be implemented:
Org.springframework.data.repository. CrudRepository
Org.springframework.data.repository. PagingAndSortingRepository
Org.springframework.data.jpa.repository. JpaRepository
Com.jspxcms.common.orm. MyJpaRepository
The dao method that needs to be implemented is put into the ResumeDaoPlus interface.
Package com.jspxcms.plug.repository
Public interface ResumeDaoPlus {
Public List getList (Integer [] siteId, Limitable limitable)
}
Package com.jspxcms.plug.repository.impl
Public class ResumeDaoImpl implements ResumeDaoPlus {
@ SuppressWarnings ("unchecked")
Public List getList (Integer [] siteId, Limitable limitable) {
JpqlBuilder jpql = new JpqlBuilder ()
Jpql.append ("from Resume bean where 1 # 1")
If (ArrayUtils.isNotEmpty (siteId)) {
Jpql.append ("and bean.site.id in (: siteId)")
Jpql.setParameter ("siteId", Arrays.asList (siteId))
}
Return jpql.list (em, limitable)
}
Private EntityManager em
@ PersistenceContext
Public void setEm (EntityManager em) {
This.em = em
}
}
JpqlBuilder is used to assemble jqpl statements, set parameters, and deal with paging problems.
Com.jspxcms.common.orm.JpqlBuilder
Chapter 6 Service6.1 configuration File / WEB-INF/classes/conf/plugin/plug/context-service.xml
Where com.jspxcms.plug.service.impl is the package where the implementation class of Service resides.
Package com.jspxcms.plug.service.impl
@ Service
@ Transactional (readOnly = true)
Public class ResumeServiceImpl implements ResumeService {
Public Page findAll (Integer siteId, Map params
Pageable pageable) {
Return dao.findAll (spec (siteId, params), pageable)
}
Public RowSide findSide (Integer siteId
Map params, Resume bean, Integer position
Sort sort) {
If (position = = null) {
Return new RowSide ()
}
Limitable limit = RowSide.limitable (position, sort)
List list = dao.findAll (spec (siteId, params), limit)
Return RowSide.create (list, bean)
}
Private Specification spec (final Integer siteId
Map params) {
Collection filters = SearchFilter.parse (params). Values ()
Final Specification fsp = SearchFilter.spec (filters
Resume.class)
Specification sp = new Specification () {
Public Predicate toPredicate (Root root
CriteriaQuery query, CriteriaBuilder cb) {
Predicate pred = fsp.toPredicate (root, query, cb)
If (siteId! = null) {
Pred = cb.and (pred, cb.equal (root.get ("site"))
. Get ("id"), siteId))
}
Return pred
}
}
Return sp
}
Private ResumeDao dao
@ Autowired
Public void setDao (ResumeDao dao) {
This.dao = dao
}
}
This class uses the Specification query method to JPA.
The background list can be sorted by any column by clicking on the header, the list page can be queried by any field, and the function of editing one or the next item on the page can be realized.
Chapter 7 label 7.1 configuration File / WEB-INF/classes/conf/plugin/plug/controller-back.xml
Add configuration to / WEB-INF/classes/conf/plugin/plug/application.properties:
FreemarkerVariables.ResumeList=PlugResumeList
Where ResumeList is the label signature.
7.2 label CLA
Package com.jspxcms.plug.web.directive
Public class ResumeListDirective implements TemplateDirectiveModel {
Public static final String SITE_ID = "siteId"
@ SuppressWarnings ({"rawtypes", "unchecked"})
Public void execute (Environment env, Map params, TemplateModel [] loopVars
TemplateDirectiveBody body) throws TemplateException, IOException {
If (loopVars.length < 1) {
Throw new TemplateModelException ("Loop variable is required.")
}
If (body = = null) {
Throw new RuntimeException ("missing body")
}
Integer [] siteId = Freemarkers.getIntegers (params, SITE_ID)
If (siteId = = null & & params.get (SITE_ID) = = null) {
SiteId = new Integer [] {ForeContext.getSiteId (env)}
}
Sort defSort = new Sort (Direction.DESC, "creationDate", "id")
Limitable limitable = Freemarkers.getLimitable (params, defSort)
List list = service.findList (siteId, limitable)
LoopVars [0] = env.getObjectWrapper () .wrap (list)
Body.render (env.getOut ())
}
@ Autowired
Private ResumeService service
}
Chapter 8 internationalization 8.1 configuration add the following configuration in / WEB-INF/classes/conf/plugin/plug/application.properties:
Background internationalization file
MessageSource.basenames.plug=/WEB-INF/messages/plugin/plug/plug
Front desk internationalization document
MessageSource.basenames.plugfore=/WEB-INF/messages/plugin/plugfore/plugfore
Where plug in messageSource.basenames.plug is usually the name of the folder where the configuration file is located, which can be changed to another name, but cannot be duplicated with other related configurations.
8.2 internationalized file / WEB-INF/messages/plugin/plug/plug is the folder and file name where the internationalized file is located.
This is the end of the article on "what is the method of non-intrusive secondary development of Jspxcms". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the method of non-invasive secondary development of Jspxcms". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.