<%@ page contentType="text/html; charset=gbk" language="java"%>
<%
String SubmitGoKind = request.getParameter("SubmitGoKind");
String SubmitCopy = request.getParameter("SubmitCopy");
String Submitdel = request.getParameter("Submitdel");
//>---------------------------move
if (SubmitGoKind != null)
{
//操作转向
}
//<---------------------------move
//<---------------------------copy
if (SubmitCopy != null)
{
//操作拷贝
}
//<---------------------------copy
//>---------------------------delete
if (Submitdel != null)
{
//操作删除
}
//<---------------------------delete
%>
<html>
<body>
<form id="form1" name="form1" method="post" action="?">
<input type="submit" name="SubmitGoKind" value="转向" />
<input type="submit" name="SubmitCopy" value="拷贝" />
<input type="submit" name="Submitdel" value="删除" />
<!--其他显示内容-->
</form>
</body>
</html>
//Sober会更具◎标签自动创建表
@Table(name = "数据库表名称", caption = "描述信息")
public class Bean implements Serializable
{
@Id(auto = true,type="serial")
@Column(caption = "ID号", length = 50, notNull = true)
private String id;
@Column(caption = "标题", length = 4, option = "0:普通;1:投票;2:辩论;3:活动", valid="inArray[0,1,2,3]",notNull = true, defaultValue = "0")
private int threadType = 0;
@Column(caption = "标题", length = 200, notNull = true)
private String title = "";
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public int getThreadType()
{
return threadType;
}
public void setThreadType(int threadType)
{
this.threadType = threadType;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
}package com.jspx.example;
import com.jspx.txweb.support.TemplateSupport;
import java.util.List;
import java.util.ArrayList;
public class HelloListAction extends TemplateSupport
{
public HelloListAction()
{
}
//这里可以提供给模版调用从而实现模版和程序的交互
public List<String> getList()
{
List<String> list = new ArrayList<String>();
list.add("one");
list.add("two");
list.add("three");
list.add("four");
list.add("five");
list.add("six");
list.add("seven");
list.add("eight");
list.add("nine");
list.add("ten");
return list;
}
//如何你在配置配置了执行方法,先执行你的执行方法在执行execute
public String execute() throws Exception
{
return SUCCESS;
}
}
FriendLink一般情况需要处理的所以动作。@Operate就相当早期使用的 request.getParameter("submit") != null;来判断是否运行函数。package jspx.jcms.admin;
import com.jspx.txweb.annotation.Validate;
import com.jspx.txweb.annotation.Operate;
import com.jspx.validator.impl.ValidatorDataType;
import com.jspx.utils.RequestUtil;
import com.jspx.utils.StringUtil;
import com.jspx.sober.criteria.expression.Expression;
import jspx.jcms.env.JcmsIoc;
import jspx.jcms.view.FriendLinkView;
import jspx.service.friedlink.FriendLink;
import jspx.user.table.UserSession;
/**
* 下边演示的是FriendLink实现的添加,删除,编辑,排序
× @标签将在后边说明,这里只是大体构架
*/
public class FriendLinkManageAction extends FriendLinkView
{
public FriendLinkManageAction()
{
}
//校验infoType为检查后保存到FieldInfo中的信息类型
//dataTypeValidator为sioc配置 formId 为检验配置的ID,
//提交表单中 post 不为空才运行校验
@Validate(infoType = ValidatorDataType.error, name = "dataTypeValidator", formId = "addfriendlinkForm", submit = "submit")
//添加
@Operate(submit = "submit")
public void save() throws Exception
{
FriendLink friendLink = (FriendLink) getBean(FriendLink.class);
if (friendLinkDAO.save(friendLink) != null)
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
//提交表单中 post 不为空才运行校验
@Validate(infoType = ValidatorDataType.error, name = "dataTypeValidator", formId = "updatefriendlinkForm", submit = "submit")
//编辑
@Operate(submit = "submit")
public void update() throws Exception
{
FriendLink friendLink = (FriendLink) getBean(FriendLink.class);
friendLink.setNamespace(JcmsIoc.namespace);
UserSession userSession = (UserSession) getUserSession();
friendLink.setPutman(userSession.getManId());
if (friendLinkDAO.update(friendLink))
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
//校验infoType为检查后保存到FieldInfo中的信息类型
//删除,多选方式
@Operate(submit = "operation", operation = "delete")
public void delete() throws Exception
{
String[] ids = getArray("id", true);
if (ids == null || ids.length < 1)
{
addFieldInfo("id", "参数错误,必须先勾选");
}
if (hasFieldInfo()) return;
boolean del = friendLinkDAO.createCriteria(FriendLink.class).add(Expression.in("id", ids)).add(Expression.eq("namespace", JcmsIoc.namespace)).delete(false);
if (del)
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
//排序
@Operate(submit = "operation", operation = "updateSortDate")
public void updateSortDate() throws Exception
{
String[] ids = getArray("id", true);
if (ids == null || ids.length < 1)
{
addFieldInfo("id", "参数错误,必须先勾选");
}
if (hasFieldInfo()) return;
boolean del = friendLinkDAO.updateSortDate(ids);
if (del)
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
//校验infoType为检查后保存到FieldInfo中的信息类型
//dataTypeValidator为sioc配置 formId 为检验配置的ID,
//提交表单中 post 不为空才运行校验
//提交表单中 post 不为空才运行 execute 方法
@Operate(submit = "operation", operation = "updateTop")
public void updateTop() throws Exception
{
String[] ids = getArray("id", true);
if (ids == null || ids.length < 1)
{
addFieldInfo("id", "参数错误,必须先勾选");
}
if (hasFieldInfo()) return;
boolean del = friendLinkDAO.updateSortType(ids, 2);
if (del)
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
//校验infoType为检查后保存到FieldInfo中的信息类型
//dataTypeValidator为sioc配置 formId 为检验配置的ID,
//提交表单中 post 不为空才运行校验
//提交表单中 post 不为空才运行 execute 方法
@Operate(submit = "operation", operation = "clearSortType")
public void clearSortType() throws Exception
{
String[] ids = getArray("id", true);
if (ids == null || ids.length < 1)
{
addFieldInfo("id", "参数错误,必须先勾选");
}
if (hasFieldInfo()) return;
if (friendLinkDAO.updateSortType(ids, 0))
{
addActionMessage("保存成功");
} else
{
addActionMessage("保存失败");
}
}
/**
* execute方法为默认执行必须执行, Operate 可以设置不执行execute
* @return
* @throws Exception
编辑的时候查询出当前编辑的对象
*/
public String execute() throws Exception
{
FriendLink friendLink = (FriendLink) friendLinkDAO.get(FriendLink.class, getString("id", true));
if (friendLink == null)
{
friendLink = new FriendLink();
}
put("friendLink", friendLink);
return SUCCESS;
}
} protected这样在Action中就不用写代码在注入了。 protected TreeItemDAO treeItemDAO;
@Ref(name = "treeItemDAO", namespace = "namespace")
public void setTreeItemDAO(TreeItemDAO treeItemDAO)
{
this.treeItemDAO = treeItemDAO;
}
JdbcOperations是sober提供的。FriendLinkDAO可以继承,public interface FriendLinkDAO extends SoberSupport这样就可以在DAO中使用Sober中提供的方法了。public class FriendLinkDAOImpl extends JdbcOperations implements FriendLinkDAO public String execute() throws Exception部分就如同html页面部分。 @Operate(submit = "submit")
public void update() throws Exception String submit = request.getParameter("submit");
if (submit!= null)
{
//操作
}Criteria接口几乎一样,推荐使用这种方式,hibernate的get方法查询不到的时候返回错误,sober返回为null,sober对数据库的支持没有hibernate那么多,但主流数据库几乎都支持了,而且都是最新版本的数据库oracle9,db2 9, mysql 4以上,psql 8.以上,mssql2000 .########################################################
#
# database config
# NOTE: Lines starting with '#' are comments.
#
#######################################################
driverClassName=smalldb.database.SSDriver
jdbcUrl=jdbc:smalldb:${databasePath}jspxnet?create=true
username=
password=
dialect=auto
show_sql=true #调试是否显示SQL
maxPoolSize=5
#######################################################
#
# Aop boot config freemaker 启动引导
# NOTE: Lines starting with '#' are comments.
# 配置是否开启AOP应用:AOP应用就是启动的时候运行一次,关闭的时候在运行一个方法
#
#######################################################
aopboot=false
########################################################
#
# template config 模板配置
# NOTE: Lines starting with '#' are comments.
#
#######################################################
#模板文件类型
templateSuffix=ftl
dateTimeFormat=yyyy-MM-dd HH:mm:ss
date_format=yyyy-MM-dd
time_format=HH:mm:ss
number_format=####.##
#URL后缀,可以改为其他文件后缀
suffix=jsp
#######################################################
#公共库,一般保存模板宏,你可以自己添加在WEB-INF/template里边
#######################################################
autoImports=scriptlib.ftl
#######################################################
#
# ajax rpc 调用,jspxnet.js里边是调用接口
# 条用这个地址,根据ioc配置就可以返回相应的数据
#
#######################################################
scriptPath=/script
rpcUrl=ajax.jsp
#######################################################
# 当不能够找到页面将跳转到此页面
#######################################################
#notFindLink=error404.html
#######################################################
#
# 日志配置 log4j config
# NOTE: Lines starting with '#' are comments.
#
#######################################################
#log4jPath=log4j.xml
error=true
fatal=true
info=true
debug=true
jspxError=true
jspxFatal=true
jspxInfo=true
#当关闭后,将页面缓存将也关闭
jspxDebug=true
#######################################################
#默认载入配置文件
#######################################################
#默认载入配置文件
txweb_config=jspx.txweb.xml
#页面缓存时间,单位秒
template_update_delay=260
#页面大小
template_cache_size=100
#######################################################
#
# txweb config
# config logined user,can in manage
# permission
#######################################################
permission=true
useThreadLocal=true
#######################################################
#
# tomcat encode china repair
# 针对Tomcat get 方式中文乱码配置,repairEncode表示是否转换乱码。
#repairRequestMethod表示专请求的那种方法,get还是post,一般只有get是乱码
#如果不需要转换repairEncode=false就可以。auto表示服务器是tomcat就转换。
#目的是方便那些使用空间租用的朋友不能修改配置,出现乱码的情况。
#
#######################################################
#get;post
repairRequestMethod=get
#auto的时候将自动识别,如果是tomcat就会为true
repairEncode=auto
#######################################################
#--graphicsenv 配置图形环境 end
#######################################################
#
# JVM 环境变量
# NOTE: Lines starting with '#' are comments.
# 系统默认编码
#######################################################
encode=UTF-8
#######################################################
#
# 构架内带了在线管理功能,并且默认定义了一套用户和权限管理接口
# 能够和txweb配置的action自动映射,来完成访问权限控制
#
#######################################################
#App 应用配置 登陆方式
guestId=0
guestName=游客