package com.athl.action;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.athl.bean.Person;
import com.athl.dao.PersonDao;
import com.athl.utils.CreateHtml;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import freemarker.template.TemplateException;
public class PersonAction extends ActionSupport implements ModelDriven<Person> {
private static final long serialVersionUID = -814210299977683837L;
private String url,msg;
private Person p;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Person getModel() {
if(p==null){
p= new Person();
}
return p;
}
public String getAll() throws Exception {
CreateHtml createHtml = new CreateHtml();
Map<String, List<Person>> map = new HashMap<String, List<Person>>();
map.put("personlist", new PersonDao().query());
System.out.println(map);
String htmlName = "personList";
String ftl = "list.ftl";
try {
createHtml.init(ftl, htmlName, map);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
url = "/"+htmlName;
return "list";
}
public String addPage() throws Exception {
CreateHtml createHtml = new CreateHtml();
//Map<String, List<Person>> map = new HashMap<String, List<Person>>();
//map.put("personlist", new PersonDao().query());
String htmlName = "add";
String ftl = "add.ftl";
try {
createHtml.init(ftl, htmlName, null);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
url = "/"+htmlName;
return "addPage";
}
public String add() throws Exception {
new PersonDao().add(p);
return getAll();
}
public String queryById() throws Exception {
CreateHtml createHtml = new CreateHtml();
Map<String, Person> map = new HashMap<String,Person>();
map.put("person", new PersonDao().queryById(p.getId()));
String htmlName = "update";
String ftl = "update.ftl";
try {
createHtml.init(ftl, htmlName, map);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
url = "/"+htmlName;
return "update";
}
public String update() throws Exception {
new PersonDao().update(p);
return getAll();
}
public String delete() throws Exception {
new PersonDao().del(p.getId());
return getAll();
}
public String queryLike() throws Exception {
CreateHtml createHtml = new CreateHtml();
Map<String, List<Person>> map = new HashMap<String, List<Person>>();
map.put("personlist", new PersonDao().queryLike(msg));
String htmlName = "personListByLike";
String ftl = "list.ftl";
try {
createHtml.init(ftl, htmlName, map);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
url = "/"+htmlName;
return "list";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
FreeMarker与struts2整合生成静态页面
共45个文件
jar:12个
xml:6个
class:5个
需积分: 9 9 下载量 41 浏览量
2017-01-07
20:16:44
上传
评论 2
收藏 4.7MB ZIP 举报
温馨提示
FreeMarker与struts2整合,一个小案例实现【增删改查】生成静态页面。内含数据库sql文件及效果图。数据库是mysql,c3p0+dbUtils实现数据操作。是一个完整的案例。
资源推荐
资源详情
资源评论
收起资源包目录
freeMarkerStrutsDemo.zip (45个子文件)
sql.sql 1KB
效果图.png 20KB
freeMarkerStrutsDemo
.project 2KB
.settings
.jsdtscope 500B
org.eclipse.core.resources.prefs 185B
org.eclipse.wst.common.component 498B
org.eclipse.jdt.core.prefs 364B
com.genuitec.eclipse.j2eedt.core.prefs 1009B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 333B
WebRoot
WEB-INF
web.xml 747B
template
list.ftl 1KB
add.ftl 771B
update.ftl 889B
lib
javassist-3.11.0.GA.jar 600KB
commons-lang3-3.1.jar 308KB
struts2-core-2.3.4.1.jar 765KB
ognl-3.0.5.jar 222KB
mysql-connector-java-5.1.12-bin.jar 716KB
commons-io-2.0.1.jar 156KB
freemarker-2.3.19.jar 909KB
commons-fileupload-1.2.2.jar 58KB
junit-4.5.jar 194KB
commons-dbutils-1.6.jar 76KB
xwork-core-2.3.4.1.jar 614KB
c3p0-0.9.1.2.jar 596KB
classes
c3p0-config.xml 1010B
com
athl
bean
Person.class 1KB
utils
CreateHtml.class 2KB
JdbcUtils.class 756B
dao
PersonDao.class 3KB
action
PersonAction.class 4KB
struts.xml 656B
index.jsp 966B
META-INF
MANIFEST.MF 36B
.myeclipse
src
c3p0-config.xml 1010B
com
athl
bean
Person.java 674B
utils
JdbcUtils.java 495B
CreateHtml.java 1KB
dao
PersonDao.java 2KB
action
PersonAction.java 3KB
struts.xml 656B
.classpath 529B
共 45 条
- 1
资源评论
朱赤墨黑
- 粉丝: 25
- 资源: 60
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功