The following is a custom labelmycontent_listFor example, explain the implementation steps:
first, a database is created with ajc_mycontentthe table, which has id,title,content three fields
Second, an entity class was created
public class Mycontent {
Private static final long serialversionuid = 1L;
Private Integer ID;
Private String title;
Private String content;
Public mycontent () {
Super ();
}
... Get Set method
}
Next, configure the configuration file for the Jc_mycontent table in hibernate
<?xml version= "1.0"?>
<! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping dtd//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">
<class name= "mycontent" table= "Jc_mycontent" >
<meta attribute= "Sync-dao" >false</meta>
<cache usage= "Read-write"/>
<id name= "id" type= "java.lang.Integer" column= "id" ><generator class= "Identity"/></id>
<property name= "title" column= "title" Type= "Java.lang.String" not-null= "true"/>
<property name= "Content" column= "content" type= "java.lang.String" not-null= "true"/>
</class>
persistent layer interfaces for interacting with databases
Public interface Mycontentdao {
Public list<mycontent> getList ();
}
Persistence Layer Implementation class
@Repository//Persistence layer
public class Mycontentdaoimpl extends Hibernatebasedao<mycontent, integer>
Implements Mycontentdao {
@SuppressWarnings ("Unchecked")
Public list<mycontent> getList () {
Return Find (Bynothing ());
}
Private Finder bynothing () {
Finder f = finder.create ();
F.append ("from mycontent");//You can add query conditions here or add various methods for dynamic query
F.setcacheable (TRUE);
return F;
}
@Override
Protected class<mycontent> Getentityclass () {
return mycontent.class;
}
}
Business Layer Interface
Public interface Mycontentmng {
Public list<mycontent> getList ();
}
Business Layer Implementation class
@Service//Business layer
@Transactional
public class Mycontentmngimpl implements MYCONTENTMNG {
@Transactional (ReadOnly = True)//configuration transaction is read-only
Public list<mycontent> getList () {
return Mycontentdao.getlist ();
}
Private Mycontentdao Mycontentdao;
@Autowired//Automatic binding
public void Setmycontentdao (Mycontentdao Mycontentdao) {
This.mycontentdao = Mycontentdao;
}
Private list<contentlistener> listenerlist;
@Autowired
public void Setlistenerlist (list<contentlistener> listenerlist) {
This.listenerlist = ListenerList;
}
}
The most important thing about the abstract class of the tag class is the GetData method, and the binding business layer(You can also add a variety of query methods, you can refer to class abstractcontentdirective).
Public abstract class Abstractmycontentdirective implements
Templatedirectivemodel {
Protected Object getData (map<string, templatemodel> params, Environment env)
Throws Templateexception {
return Mycontentmng.getlist ();
}
@Autowired
protected MYCONTENTMNG mycontentmng;
}
The most important class in the custom label inherits the abstract class above
public class Mycontentlistdirective extends Abstractmycontentdirective {
public static final String tpl_name = "Mycontent_list";
@SuppressWarnings ("Unchecked")
public void execute (Environment env, MAP params, templatemodel[] loopvars,
Templatedirectivebody body) throws Templateexception, IOException {
Get site
Cmssite site = frontutils.getsite (env);
Get the Content List
list<mycontent> list = GetList (params, env);
map<string, templatemodel> paramwrap = new hashmap<string, templatemodel> (params);
The Myout_list value is mytag_list, and the table of contents is placed
Paramwrap.put (myout_list, Default_wrapper.wrap (list));
Copy the value of the params to variable
map<string, templatemodel> origmap = directiveutils.addparamstovariable (env, paramwrap);
Not using the default template, directly using your own simple template (mycontent_list.html)
FRONTUTILS.INCLUDETPL (Tpl_name, site, params, env);
Remove the params value from the variable
Directiveutils.removeparamsfromvariable (env, Paramwrap, Origmap);
}
Protected list<mycontent> getList (map<string, templatemodel> params,
Environment env) throws Templateexception {
return Mycontentmng.getlist ();
}
}
Note: 1. Define output parameters (list data) under Freemarker Label Tool class Directiveutils:myout_list
public static final String myout_list = "Mytag_list";
2. The Declaration of each label (such as Cms_mycontent_list) is done in Jeecms-context.xml, remember that the manager, DAO Bean configuration
In addition, the configuration file Jeecms-servlet-front.xml, there is also a section on the label configuration.
under Web-inf\t\cms\www\red\tag new template mycontent_list.html, and add the following code (inside can also add some of their own style, you can refer to \t\cms_sys_defined\style_ List under Style file)
[#list Mytag_list as a]
<li><a href= "${a.title}" ><font color= ' Blue ' > ' ${a.content} ' </font></a></li>
[/#list]
In the Web-inf\t\cms\www\red\index Ere page, add the following code to the HTML.
[@cms_mycontent_list]
<ul class= "Topnews" >
</ul>
[/@cms_mycontent_list]
With these codes, you can query the data in your own table jc_mycontent and display it on the page
Blog Source Address http://blog.sina.com.cn/s/blog_71420de901019v8o.html#commonComment
Jeecms the implementation process of customizing labels and using tables that you create