第一个,明确实体类里面的属性,以本例来说,config_info表里面有id,name,value,type,typename,desc,status。这几个属性。
创建相应的实体类,生成对应的get/set方法(补充一下就是操作完了之后页面会留下记录,可以在upd 和add的jsp的form表单里面加AUTOCOMPLETE=“off” 可以之后没有记录,看的干净一点)
pojo
@Entity
@Table(name = "config_info")
public class ConfigInfo implements Serializable {
private Integer configId;
private String configName;
private String configValue;
private Integer configType;
private String configDesc;
private Integer status;
public ConfigInfo() {
}
public ConfigInfoVO convertVO(){
ConfigInfoVO vo = new ConfigInfoVO();
vo.setConfigDesc(this.configDesc);
vo.setConfigId(this.configId);
vo.setConfigName(this.configName);
vo.setStatus(this.status);
vo.setConfigType(this.configType);
vo.setConfigValue(this.configValue);
return vo;
}
public ConfigInfo(ConfigInfoVO vo){
if(vo != null) {
this.configDesc = vo.getConfigDesc();
this.configId = vo.getConfigId();
this.configName = vo.getConfigName();
this.configType = vo.getConfigType();
this.status = vo.getStatus();
this.configValue = vo.getConfigValue();
}
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "CONFIG_ID", unique = true, nullable = false)
public Integer getConfigId() {
return configId;
}
public void setConfigId(Integer configId) {
this.configId = configId;
}
@Basic
@Column(name = "CONFIG_NAME")
public String getConfigName() {
return configName;
}
public void setConfigName(String configName) {
this.configName = configName;
}
@Basic
@Column(name = "CONFIG_VALUE", columnDefinition = "TEXT")
public String getConfigValue() {
return configValue;
}
public void setConfigValue(String configValue) {
this.configValue = configValue;
}
@Basic
@Column(name = "CONFIG_TYPE")
public Integer getConfigType() {
return configType;
}
public void setConfigType(Integer configType) {
this.configType = configType;
}
@Basic
@Column(name = "CONFIG_DESC")
public String getConfigDesc() {
return configDesc;
}
public void setConfigDesc(String configDesc) {
this.configDesc = configDesc;
}
@Basic
@Column(name = "STATUS")
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfigInfo that = (ConfigInfo) o;
return Objects.equals(configId, that.configId) &&
Objects.equals(configName, that.configName) &&
Objects.equals(configValue, that.configValue) &&
Objects.equals(configType, that.configType) &&
Objects.equals(configDesc, that.configDesc) &&
Objects.equals(status, that.status);
}
@Override
public int hashCode() {
return Objects.hash(configId, configName, configValue, configType, configDesc, status);
}
}
vo
public class ConfigInfoVO extends BaseVO {
private Integer configId;
private String configName;
private String configValue;
private Integer configType;
private String configTypeName;
private String configDesc;
private Integer status;
public Integer getConfigId() {
return configId;
}
public void setConfigId(Integer configId) {
this.configId = configId;
}
public String getConfigName() {
return configName;
}
public void setConfigName(String configName) {
this.configName = configName;
}
public String getConfigValue() {
return configValue;
}
public void setConfigValue(String configValue) {
this.configValue = configValue;
}
public Integer getConfigType() {
return configType;
}
public void setConfigType(Integer configType) {
this.configType = configType;
}
public String getConfigDesc() {
return configDesc;
}
public void setConfigDesc(String configDesc) {
this.configDesc = configDesc;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getConfigTypeName() {
return configTypeName;
}
public void setConfigTypeName(String configTypeName) {
this.configTypeName = configTypeName;
}
}
给自己提醒一下在数据库里面,config_id是主键
然后做的就是根据实体类写dao层,dao层是数据访问层,来对这个表进行相应的数据操作。
IConfiiInfoDao:dao层的接口
public interface IConfigInfoDao {
/**
* 查询所有配置信息
* @param configType 系统配置类型
* @return
* @throws DAOException
*/
public Map queryConfigInfo(ConfigInfoQryVO qryvo) throws DAOException;
/**
* 查询系统配置详情
* @param configId 系统配置ID
* @return
* @throws DAOException
*/
public ConfigInfoVO getConfigInfo(int configId) throws DAOException;
/**
* 修改系统配置
* @param vo 修改后的数据
* @return
* @throws DAOException
*/
public boolean updConfigInfo(ConfigInfoVO vo) throws DAOException;
/**
* 自己来写的ADD方法 没用的话方便删除看正确的代码
* @param vo
* @return
* @throws DAOException
*/
public ConfigInfoVO addConfigInfo(ConfigInfoVO vo) throws DAOException;
/**
* 来写的Delete方法
*/
public ConfigInfoVO deleteConfigInfo(int config_id) throws DAOException;
}
接口里面具体写的是抽象的方法,然后就是根据接口里面的方法,在dao层里面写具体的实现方法。实现方法:ConfigInfoDaoImpl
import java.util.*;
@Repository
public class ConfigInfoDaoImpl implements IConfigInfoDao {
private Logger logger = Logger.getLogger(ConfigInfoDaoImpl.class);
@Autowired
private BaseHibernateDao baseHibernateDao;
@Override
public ConfigInfoVO getConfigInfo(int configId) throws DAOException {
logger.debug("enter into getConfigInfo of ConfigInfoDaoImpl");
try {
Object obj = baseHibernateDao.get(ConfigInfo.class,configId);
if(obj != null){
return ((ConfigInfo)obj).convertVO();
}
return null;
} catch (RuntimeException e) {
logger.error("RuntimeException in getConfigInfo of ConfigInfoDaoImpl:" ,e);
throw new DAOException("RuntimeException in getConfigInfo of ConfigInfoDaoImpl:" ,e);
}
}
@Override
public Map queryConfigInfo(ConfigInfoQryVO qryvo) throws DAOException {
logger.debug("enter into queryConfigInfo of ConfigInfoDaoImpl");
if(qryvo == null) {
logger.error("parameter is null in queryConfigInfo of ConfigInfoDaoImpl");
throw new DAOException("parameter is null in queryConfigInfo of ConfigInfoDaoImpl");
}
HashMap map=null;
int totalNum = 0;
try {
//准备组装查询列表头SQL
StringBuffer qrySql = new StringBuffer(" from ConfigInfo t where 1=1 ");
//准备组装查询总数头SQL
StringBuffer countSql = new StringBuffer(" select count(*) from ConfigInfo t where 1=1");
//准备组装条件SQL
StringBuffer whereSql = new StringBuffer();
//组装查询条件
if(qryvo.getConfigType() != null && qryvo.getConfigType() > 0) {
whereSql.append(" and t.configType=").append(qryvo.getConfigType());
}
if(qryvo.getConfigName() != null && !"".equals(qryvo.getConfigName().trim())){
whereSql.append(" and t.configName like '%").append(qryvo.getConfigName()).append("%' ");
}
//如果同一条件下第一次查询需统计总数
if(qryvo.getIsFirst()){
String countSqlStr = countSql.append(whereSql).toString();
logger.debug("select is first, sql = " + countSqlStr);
totalNum = baseHibernateDao.countByConditions(countSqlStr);
}
//组合查询列表SQL并加入排序
String qrySqlStr = qrySql.append(whereSql).append(" order by configId asc").toString();
logger.debug("qrySqlStr = " + qrySqlStr);
List list = baseHibernateDao.listAllByConditionsAndPaging(qrySqlStr, qryvo.getBeginIndex(), qryvo.getPageSize());
if (list != null && !list.isEmpty()) {
map = new HashMap();
map.put("list", copy(list));
map.put("totalNum", totalNum);
}
return map;
}catch (RuntimeException e) {
logger.error("RuntimeException in queryConfigInfo of ConfigInfoDaoImpl:" ,e);
throw new DAOException("RuntimeException in queryConfigInfo of ConfigInfoDaoImpl:" ,e);
}
}
/**
* 集合对象转化
* @param list
* @return
*/
private List<ConfigInfoVO> copy(List<ConfigInfo> list){
if(list == null || list.isEmpty()){
return null;
}
List<ConfigInfoVO> volist=new ArrayList<ConfigInfoVO>();
for (ConfigInfo pojo : list) {
volist.add(pojo.convertVO());
}
return volist;
}
@Override
public boolean updConfigInfo(ConfigInfoVO vo) throws DAOException {
try {
baseHibernateDao.update(new ConfigInfo(vo));
} catch (RuntimeException e) {
logger.error("RuntimeException in updConfigInfo of ConfigInfoDaoImpl:" ,e);
throw new DAOException("RuntimeException in updConfigInfo of ConfigInfoDaoImpl:" ,e);
}
return true;
}
/**
* 增加方法的实现(模仿一下IUserGRoupInfoDao里的ADD方法实现)
* @param vo
* @return
* @throws DAOException
*/
@Override
public ConfigInfoVO addConfigInfo(ConfigInfoVO vo) throws DAOException {
logger.debug("enter into add of ConfigInfoDaoImml");
if(vo == null) {
logger.error("parameter is error");
throw new DAOException("parameter is error");
}
ConfigInfoVO configInfoVO = new ConfigInfoVO();
configInfoVO.setConfigId(DictionaryConstant.RESULT_FAILURE);
try{
ConfigInfo pojo = new ConfigInfo(vo);
int id = baseHibernateDao.save(pojo);
baseHibernateDao.flush();
configInfoVO.setConfigId(id);
}catch (Exception e) {
logger.error("Exception in add of ConfigInfoDaoImpl", e);
throw new DAOException("Exception in add of ConfigIngoDaoImpl",e);
}
return configInfoVO;
}
/**
* 写一个删除的方法 来对已经存在了的configinfo进行删除
*/
@Override
public ConfigInfoVO deleteConfigInfo(int config_id) throws DAOException {
logger.debug("enter into delete of ConfigInfo");
if (config_id <= 0 ){
logger.error("parameter is null in delete of ConfigInfoImpl");
throw new DAOException("parameter is null in delete of RoleInfoDaoImpl");
}
ConfigInfoVO con = new ConfigInfoVO();
con.setConfigId(Constant.RESULT_FAILURE);
try {
baseHibernateDao.delete(ConfigInfo.class,config_id);
con.setConfigId(Constant.RESULT_SUCCESS);
} catch (Exception e) {
logger.error("Exception in delete of RoleInfoDaoImpl:", e);
throw new DAOException("Exception in delete of RoleInfoDaoImpl:", e);
}
return con;
}
}
dao层是操作的实现方法,然后就是写service层里面的内容。有接口和具体实现。
IConfigInfoService
public interface IConfigInfoService {
/**
* 查询所有配置信息
* @return
* @throws ServiceException
*/
public Map queryConfigInfo(ConfigInfoQryVO qryvo) throws ServiceException;
/**
* 查询系统配置详情
* @param configId 系统配置ID
* @return
* @throws ServiceException
*/
public ConfigInfoVO getConfigInfo(int configId) throws ServiceException;
/**
* 修改系统配置
* @param vo 修改后的数据
* @return
* @throws ServiceException
*/
public boolean updConfigInfo(ConfigInfoVO vo) throws ServiceException;
/**
* 实现add方法
* @param configInfoVO
* @return
* @throws ServiceException
*/
public ConfigInfoVO add(ConfigInfoVO configInfoVO) throws ServiceException;
/**
* 实现delete方法 照着增加写删除
*/
public ConfigInfoVO del(int config_id) throws ServiceException;
}
写完了接口写具体实现方法类
ConfigInfoServiceImpl
@Service
@Transactional(propagation=Propagation.REQUIRED, rollbackFor=ServiceException.class)
public class ConfigInfoServiceImpl implements IConfigInfoService {
private Logger logger = Logger.getLogger(ConfigInfoServiceImpl.class);
@Autowired
private IConfigInfoDao configInfoDao ;
@Override
public ConfigInfoVO getConfigInfo(int configId) throws ServiceException {
logger.debug("enter into getConfigInfo of ConfigInfoServiceImpl");
if(configId <= 0) {
logger.error("parmeter is null in getConfigInfo of ConfigInfoServiceImpl");
throw new ServiceException("parmeter is null in getConfigInfo of ConfigInfoServiceImpl");
}
try {
return configInfoDao.getConfigInfo(configId);
}catch (DAOException e) {
logger.error("ServiceException in getConfigInfo of ConfigInfoServiceImpl" , e);
throw new ServiceException("ServiceException in getConfigInfo of ConfigInfoServiceImpl" , e);
}
}
@Override
public Map queryConfigInfo(ConfigInfoQryVO qryvo) throws ServiceException {
logger.debug("enter into queryConfigInfo of ConfigInfoServiceImpl");
if(qryvo == null) {
logger.error("parmeter is null in queryConfigInfo of ConfigInfoServiceImpl");
throw new ServiceException("parmeter is null in queryConfigInfo of ConfigInfoServiceImpl");
}
try {
return configInfoDao.queryConfigInfo(qryvo);
}catch (DAOException e) {
logger.error("ServiceException in queryConfigInfo of ConfigInfoServiceImpl" , e);
throw new ServiceException("ServiceException in queryConfigInfo of ConfigInfoServiceImpl" , e);
}
}
@Override
public boolean updConfigInfo(ConfigInfoVO vo) throws ServiceException {
logger.debug("enter into updConfigInfo of ConfigInfoServiceImpl");
if(vo == null) {
logger.error("parmeter is null in updConfigInfo of ConfigInfoServiceImpl");
throw new ServiceException("parmeter is null in ConfigInfoVO of ConfigInfoServiceImpl");
}
try {
return configInfoDao.updConfigInfo(vo);
}catch (DAOException e) {
logger.error("ServiceException in updConfigInfo of ConfigInfoServiceImpl" , e);
throw new ServiceException("ServiceException in updConfigInfo of ConfigInfoServiceImpl" , e);
}
}
//仿照的增加方法,调用了dao层里面的增加
@Override
public ConfigInfoVO add(ConfigInfoVO configInfoVO) throws ServiceException {
try {
configInfoVO = configInfoDao.addConfigInfo(configInfoVO);
} catch (Exception e) {
logger.error("Exception in SaveConfigInfoVo of ConfigInfoServiceImpl",e);
throw new ServiceException("Exception in SaveConfigInfoVo of ConfigInfoServieImpl",e);
}
return configInfoVO;
}
//照着CertChainServiceImpl的方法来写删除
@Override
public ConfigInfoVO del(int config_id) throws ServiceException {
if (config_id == 0) {
logger.error("parmeter is null in delConfigInfoServiceImpl");
throw new ServiceException("parmeter is null in delConfigInfoImpl ");
}
try {
return configInfoDao.deleteConfigInfo(config_id);
} catch (Exception e) {
logger.error("Exception in DelConfigInfoVo of ConfigInfoServiceImpl",e);
throw new ServiceException("Exception in DelConfigInfoVo of ConfigInfoServiceImpl",e);
}
}
}
已经完成了实体类,dao层,service层,然后就是写Controller层,来根据相应的操作来进行页面间的跳转。
QryConfigInfoAction
@Controller
public class QryConfigInfoAction extends ActionSupport {
private Logger logger = Logger.getLogger(QryConfigInfoAction.class);
@Autowired
private IConfigInfoService configInfoService;
private ConfigInfoQryVO qryvo = new ConfigInfoQryVO();
private List<ConfigInfoVO> configInfos;
private String flag;
public String execute() throws Exception {
logger.debug("enter into QryConfigInfoAction");
if(flag != null && flag.equals("1")) {
qryvo.setIsFirst(true);
}
//过滤空格
if(qryvo.getConfigName() != null)
qryvo.setConfigName(qryvo.getConfigName().trim());
qryvo.setIsNeedPage(true);//需要分页
Map map = configInfoService.queryConfigInfo(qryvo);
int totalNum = qryvo.getTotalNum();
if(map != null && map.size() > 0) {
configInfos = (List) map.get("list");
if(qryvo.getIsFirst()) {
totalNum = (Integer) map.get("totalNum");
qryvo.setTotalNum(totalNum);
}
Map appMap = ActionContext.getContext().getApplication();
//设置分页
PageUtil util = new PageUtil(qryvo.getTotalNum(), qryvo.getPageSize(), qryvo.getPageNo());
qryvo.setPageUtil(util.getTxtPageBar());
}
//补充列表
if(configInfos == null){
configInfos = new ArrayList<ConfigInfoVO>();
}
int leftrow = qryvo.getPageSize() - configInfos.size();
ConfigInfoVO tempvo = null;
for (int i = 0; i < leftrow; i++) {
tempvo = new ConfigInfoVO();
configInfos.add(configInfos.size(), tempvo);
}
return "success";
}
public ConfigInfoQryVO getQryvo() {
return qryvo;
}
public void setQryvo(ConfigInfoQryVO qryvo) {
this.qryvo = qryvo;
}
public List getConfigInfos() {
return configInfos;
}
public void setConfigInfos(List<ConfigInfoVO> configInfos) {
this.configInfos = configInfos;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
}
UpdateConfigAction
@Controller
public class UpdateConfigAction extends ActionSupport {
private Logger logger = Logger.getLogger(UpdateConfigAction.class);
@Autowired
private IConfigInfoService configInfoService;
private ConfigInfoVO configInfoVO;
private String flag;
private int id;
public String execute() throws Exception {
logger.debug("enter into UpdateConfigAction");
ConfigInfoVO oldvo = configInfoService.getConfigInfo(configInfoVO.getConfigId());
if(oldvo == null) {
logger.error("未查询到参数信息");
return "error";
}
oldvo.setConfigValue(configInfoVO.getConfigValue());
configInfoService.updConfigInfo(oldvo);
ConfigInfoUtil.configMap.clear();
return "success";
}
@Override
public void validate() {
this.clearFieldErrors();
if(flag == null) {
}
if(flag != null && flag.equals("preupd")){
try {
configInfoVO = configInfoService.getConfigInfo(id);
Map appMap = ActionContext.getContext().getApplication();
}catch (ServiceException e) {
logger.error("" , e);
this.addFieldError("name_error", "");
}
this.addFieldError("preupd", "preupd");
}
}
public ConfigInfoVO getConfigInfoVO() {
return configInfoVO;
}
public void setConfigInfoVO(ConfigInfoVO configInfoVO) {
this.configInfoVO = configInfoVO;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
AddConfigInfoAction
@Controller
public class AddConfigInfoAction extends ActionSupport {
private Logger logger = Logger.getLogger(AddConfigInfoAction.class);
@Autowired
private IConfigInfoService configInfoService;
private ConfigInfoVO configInfoVO;
public ConfigInfoVO getConfigInfoVO() {
return configInfoVO;
}
public void setConfigInfoVO(ConfigInfoVO configInfoVO) {
this.configInfoVO = configInfoVO;
}
public String execute() throws Exception {
logger.debug("enter into UpdateConfigAction");
configInfoVO.setStatus(DictionaryConstant.STATUS_OK);
configInfoService.add(configInfoVO);
return "success";
}
}
DeleteConfigInfoAction
@Controller
public class DeleteConfigInfoAction extends ActionSupport {
private Logger logger = Logger.getLogger(DeleteConfigInfoAction.class);
@Autowired
private IConfigInfoService configInfoService;
private ConfigInfoVO configInfoVO;
private int id;
public ConfigInfoVO getConfigInfoVO() {
return configInfoVO;
}
public void setConfigInfoVO(ConfigInfoVO configInfoVO) {
this.configInfoVO = configInfoVO;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String execute()throws Exception {
try {
configInfoService.del(id);
return SUCCESS;
} catch (ServiceException e) {
e.printStackTrace();
}
return ERROR;
// configInfoService.del(id);
// return "success";
}
}
这几个写完了就是来写view层,就是相应的页面显示。
mgr.jsp就是具体的显示页面,包括了查询的实现
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="com.custle.svs.common.constant.PrivilegeConstant"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="p" uri="/privilege-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>基本配置</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="<%=basePath%>/css/common.css" type="text/css" rel="stylesheet" />
<link href="<%=basePath%>/css/main_user.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/jquery.jslides.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/odd.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>
<style>
html {
overflow-x: hidden;
}
html,body {
height: 100%;
margin: 0px;
}
.cuttitle{ width: 200px; overflow: hidden; white-space: nowrap; -o-text-overflow: ellipsis; text-overflow: ellipsis; }
</style>
</head>
<body >
<div class="center_box" style="border: 0px;">
<form name="searchform" action="<%=basePath%>/config/qry.action?flag=1" method="post" >
<s:hidden name="qryvo.pageNo" id="pageNum" />
<s:hidden name="qryvo.totalNum"/>
<s:hidden name="qryvo.isFirst" value="false"/>
<h2>基本配置列表
<span>
<div class="floatleft" style="position:relative; ">
<%--<s:select cssClass="inputbox" cssStyle="margin-top:7px;float:left;width:180px;" name="qryvo.configType"
list="#application.CONFIG_TYPE" listKey="value" listValue="name" headerKey="-1" headerValue="请选择参数类型">
</s:select>--%>
</div>
<div class="floatleft" style=" margin-left:10px;">
<input type="submit" class="btn_menu " value="查询" />
<input type="button" class="btn_menu " value="添加" style="margin-left: 10px;display: inline-block;width: 120px;" onclick="javascript:window.location.href='<%=path %>/jsp/configinfo/configadd.jsp'"/>
</div>
</span>
</h2>
</form>
<div style="overflow:hidden;zoom:1">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list_tab">
<col width="" />
<col width="" />
<col width="" />
<col width="" />
<col width="" />
<tr>
<th>参数类型</th>
<th>参数名称</th>
<th>参数值</th>
<th>参数描述</th>
<th>
<div class="aligncenter">操作</div>
</th>
</tr>
<s:iterator value="configInfos">
<tr>
<td><s:property value="configTypeName" default=""/></td>
<td><s:property value="configName" default=""/></td>
<td><div class="cuttitle"><s:property value="configValue" default=""/></div></td>
<td class="alignleft" style="font-size:12px;"><s:property value="configDesc" default=""/></td>
<td align="center">
<s:if test="configId != null">
<input name="editButton" type="button" class="edit_menu btn" value="修改"
onclick="location.href='<%=basePath%>/config/upd.action?flag=preupd&id=<s:property value="configId" default=""/>'" />
<input name="editButton" type="button" class="edit_menu btn" value="删除"
onclick="location.href='<%=basePath%>/config/del.action?flag=preupd&id=<s:property value="configId" default=""/>'" />
</s:if>
<s:else>
</s:else>
</td>
</tr>
</s:iterator>
</table>
<div class="page_box">
<s:property value="qryvo.pageUtil" default="" escapeHtml="false"/>
<s:if test="qryvo.totalNum == 0">
<div class="info"><strong>没有记录</strong></div>
</s:if>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
function pageSubmit(pageno){
document.getElementById("pageNum").value=pageno;
document.forms[0].action="<%=path %>/config/qry.action";
document.forms[0].submit();
}
</script>
add.jsp就是进行增加功能的页面显示,尤其要注意的是在每个对应数据的位置要一一对应,要根据config_info表里面的数据来填写具体的内容。
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="com.custle.svs.common.constant.DictionaryConstant"%>
<%@page import="com.custle.svs.common.constant.PrivilegeConstant"%>
<%@page import="com.custle.svs.common.util.DateFormater"%>
<%@page import="java.util.Date"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/privilege-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path;
%>
<!DOCTYPE HTML>
<html>
<head>
<title>添加基本配置</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="<%=basePath%>/css/common.css" type="text/css" rel="stylesheet" />
<link href="<%=basePath%>/css/main_user.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath %>/js/judge.js"></script>
<style>
html {
overflow-x: hidden;
}
html,body {
height: 100%;
margin: 0px;
}
</style>
</head>
<body>
<div class="center_box" style="border: 0px;">
<h2>添加信息</h2>
<div style="overflow:hidden;zoom:1; margin-top:20px;">
<form action="<%=basePath %>/config/add.action" id="addform" name="addform" method="post" enctype="multipart/form-data">
<input type="hidden" name="log" id="log"/>
<table width="100%" class="table_info">
<tr>
<th width="200"><em>*</em> 参数名称:</th>
<td>
<s:textfield type="text" cssClass="inputbox" id="configid" name="configInfoVO.configName" maxlength="32" style="width: 300px;"/>
</td>
</tr>
<tr>
<th>参数类型:</th>
<td>
<s:textfield type="text" cssClass="inputbox" id="configtype" name="configInfoVO.configType" maxlength="11" style="width: 50px;"/>
</td>
</tr>
<tr>
<th><em>*</em> 参数值:</th>
<td>
<s:textarea class="inputbox" cols="800" rows="10" style="height:200px;width:450px;" id="configValue" name="configInfoVO.configValue" onchange="checkValue()"></s:textarea>
<br/><span style="clear:left; color:#506470;">(最多输入4096个字符)</span>
</td>
</tr>
<tr>
<th width="200"> 参数描述:</th>
<td>
<s:textfield type="text" cssClass="inputbox" id="configdesc" name="configInfoVO.configDesc" maxlength="11" style="width: 50px;"/>
</td>
</tr>
<tr>
<th></th>
<td align="center">
<input name="submitbutton" id="submitbutton" type="button" class="btn_common" value="保存" onClick="mysubmit();" />
<input name="backbutton" type="button" class="btn_cancel" onclick="history.go(-1);" value="返回">
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<script type="text/javascript">
var check = true;
function mysubmit(){
if(!checkForm()){
return false;
}
if(!addLog()){
return false;
}
$("#submitbutton").attr("disabled","disabled");
$("#submitbutton").attr("value","处理中···");
$("#addform").submit();
}
function checkForm(){
check = true;
checkValue();
return check;
}
function checkValue(){
var configValue = document.getElementById("configValue");
if(configValue.value == null || configValue.value<=0){
$("#configValue_error").text("请输入参数值!");
$("#configValue_error").css("display","block");
$("#configValue").css("border","1px solid #f60");
$("#configValue").focus();
check = false;
return;
}else{
$("#configValue").css("border","1px solid #ddd");
$("#configValue_error").text("");
$("#configValue_error").css("display","none");
}
if(configValue.value.length>4096){
$("#configValue_error").text("最多输入4096个字符!");
$("#configValue_error").css("display","block");
$("#configValue").css("border","1px solid #f60");
$("#configValue").focus();
check = false;
return;
}else{
$("#configValue").css("border","1px solid #ddd");
$("#configValue_error").text("");
$("#configValue_error").css("display","none");
}
}
function addLog(){
var log = new Object();
log.actiontype='<%=DictionaryConstant.OPTYPE_5%>';//系统配置
log.actionbegintime='<<%=DateFormater.dateToString(DateFormater.FORMART4,new Date())%>';
log.actionobject='修改系统参数';
log.msg='{ 参数名称 : ${configInfoVO.configName} }';
var strlog = getLog(log);
if(strlog=='ERROR'){
return false;
}
strlog = strlog.replace("/\+/g",'%2B');
document.getElementById('log').value=strlog;
return true;
}
</script>
upd.jsp 进行修改更新的页面,上面的add.jsp其实是根据这个来改的。
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="com.custle.svs.common.constant.DictionaryConstant"%>
<%@page import="com.custle.svs.common.constant.PrivilegeConstant"%>
<%@page import="com.custle.svs.common.util.DateFormater"%>
<%@page import="java.util.Date"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/privilege-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>修改基本配置</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="<%=basePath%>/css/common.css" type="text/css" rel="stylesheet" />
<link href="<%=basePath%>/css/main_user.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath %>/js/judge.js"></script>
<style>
html {
overflow-x: hidden;
}
html,body {
height: 100%;
margin: 0px;
}
</style>
</head>
<body>
<div class="center_box" style="border: 0px;">
<h2>修改<s:property value="configInfoVO.configName"/></h2>
<div style="overflow:hidden;zoom:1; margin-top:20px;">
<form action="<%=basePath %>/config/upd.action" method="post" id="updform" name="updform" >
<input type="hidden" name="log" id="log"/>
<s:hidden name="configInfoVO.configId"/>
<input type="hidden" name="id" id="id" value="${configInfoVO.configId}"/>
<table width="100%" class="table_info">
<tr>
<th width="200">参数名称:</th>
<td>
<s:property value="configInfoVO.configName"/>
</td>
</tr>
<tr>
<th>参数类型:</th>
<td>
<s:property value="configInfoVO.configType"/>
</td>
</tr>
<tr>
<th><em>*</em> 参数值:</th>
<td>
<s:textarea class="inputbox" cols="800" rows="10" style="height:200px;width:450px;" id="configValue" name="configInfoVO.configValue" onchange="checkValue()"></s:textarea>
<br/><span style="clear:left; color:#506470;">(最多输入4096个字符)</span>
</td>
</tr>
<tr>
<th width="200"></th>
<td>
<span id="configValue_error" class="error" style="display: none; float: left;"></span>
</td>
</tr>
<tr>
<th>参数描述:</th>
<td>
<s:property value="configInfoVO.configDesc"/>
</td>
</tr>
<tr>
<th></th>
<td>
<input name="submitbutton" id="submitbutton" type="button" class="btn_common" value="保存" onclick="mysubmit();" />
<input name="backbutton" type="button" class="btn_cancel" value="返回" onclick="history.go(-1);"/>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<script type="text/javascript">
var check = true;
function mysubmit(){
if(!checkForm()){
return false;
}
if(!addLog()){
return false;
}
$("#submitbutton").attr("disabled","disabled");
$("#submitbutton").attr("value","处理中···");
$("#updform").submit();
}
function checkForm(){
check = true;
checkValue();
return check;
}
function checkValue(){
var configValue = document.getElementById("configValue");
if(configValue.value == null || configValue.value<=0){
$("#configValue_error").text("请输入参数值!");
$("#configValue_error").css("display","block");
$("#configValue").css("border","1px solid #f60");
$("#configValue").focus();
check = false;
return;
}else{
$("#configValue").css("border","1px solid #ddd");
$("#configValue_error").text("");
$("#configValue_error").css("display","none");
}
if(configValue.value.length>4096){
$("#configValue_error").text("最多输入4096个字符!");
$("#configValue_error").css("display","block");
$("#configValue").css("border","1px solid #f60");
$("#configValue").focus();
check = false;
return;
}else{
$("#configValue").css("border","1px solid #ddd");
$("#configValue_error").text("");
$("#configValue_error").css("display","none");
}
}
function addLog(){
var log = new Object();
log.actiontype="<%=DictionaryConstant.OPTYPE_5%";//系统配置
log.actionbegintime='<<%=DateFormater.dateToString(DateFormater.FORMART4,new Date())%>';
log.actionobject='修改系统参数';
log.msg='{ 参数名称 : ${configInfoVO.configName} }';
var strlog = getLog(log);
if(strlog=='ERROR'){
return false;
}
strlog = strlog.replace("/\+/g",'%2B');
document.getElementById('log').value=strlog;
return true;
}
</script>
最后还有一个挺关键的东西就是配置好相应的struts,要不然没有拦截器来对这些活动进行相应的处理。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- struts2委托spring管理 -->
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.locale" value="zh_CN" />
<!-- 默认的视图主题 -->
<constant name="struts.ui.theme" value="simple" />
<!--解决乱码 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
<!--设置特殊不经过拦截器的url-->
<constant name="struts.action.excludePattern" value="/ueditor/.*"/>
<!-- 设置上传文件的临时文件夹,默认使用javax.servlet.context.tempdir -->
<constant name="javax.servlet.context.tempdir" value="/temp" />
<constant name="struts.multipart.saveDir" value="/temp" />
<constant name="struts.multipart.maxSize" value="209715200"/>
<include file="struts-default.xml"/>
<package name="commonStack" extends="struts-default">
<!-- 定义全局处理结果 未登录转到此页 -->
<global-results>
<!-- 逻辑名为login的结果,映射到/login.jsp页面 -->
<result name="sessionout">/jsp/common/sessionout.jsp</result>
<result name="error">/jsp/common/error.jsp</result>
<result name="success">/jsp/common/success.jsp</result>
<!-- 如果重复提交,跳转到resubmit.jsp页面 -->
<result name="invalid.token">/jsp/common/resubmit.jsp</result>
<!-- 弹出层跳转页面 -->
<result name="success.pop">/jsp/common/success_pop.jsp</result>
<result name="error.pop">/jsp/common/error_pop.jsp</result>
</global-results>
</package>
<!-- 系统参数配置 -->
<package name="config" extends="commonStack" namespace="/config">
<action name="qry" class="com.custle.svs.controller.configinfo.QryConfigInfoAction">
<result>/jsp/configinfo/configmgr.jsp</result>
</action>
<action name="upd" class="com.custle.svs.controller.configinfo.UpdateConfigAction">
<result name="input">/jsp/configinfo/configupd.jsp</result>
<result name="success" type="redirect">qry.action</result>
</action>
<action name="add" class="com.custle.svs.controller.configinfo.AddConfigInfoAction">
<result name="input">/jsp/configinfo/configadd.jsp</result>
<result name="success" type="redirect">qry.action</result>
</action>
<action name="del" class="com.custle.svs.controller.configinfo.DeleteConfigInfoAction">
<result name="success" type="redirect">qry.action</result>
</action>
</package>
</struts>
效果图