系统参数设计,即用户词典,把一些词组单独放一表中,系统启动即加载到Application中

33 篇文章 0 订阅
32 篇文章 0 订阅

DictionaryAction.java

package cn.buaa.scm.action;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.buaa.scm.entity.Dictionary;
import cn.buaa.scm.service.DictionaryService;

@Controller
@RequestMapping(value="/dictionary")
public class DictionaryAction extends BaseAction {
	@Resource
	private DictionaryService dictionaryService;
	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}
	
	@RequestMapping(value="/getDictionary")
	public @PostConstruct void getDictionary(){
		System.out.println("-----------------hello看到我了吗,我是用户词典----------------------");
		List<Dictionary> dictionaryList = dictionaryService.select();
		Map<String,Object> sysParam = new LinkedHashMap<>();
		Map<String,Object> supType = new LinkedHashMap<>();
		Map<String,Object> goods_color = new LinkedHashMap<>();
		if(dictionaryList.size()>0){
			for(Dictionary dictionary:dictionaryList){
				if(dictionary.getDicField().equalsIgnoreCase("supType")){
					supType.put(""+dictionary.getDicValue(), dictionary.getDicText());
					System.out.println("供应商"+dictionary.getDicValue()+","+dictionary.getDicText());
				}else if(dictionary.getDicField().equalsIgnoreCase("goods_color")){
					goods_color.put(""+dictionary.getDicValue(), dictionary.getDicText());
					System.out.println("颜色"+dictionary.getDicValue()+","+dictionary.getDicText());
				}
			}
			sysParam.put("supType", supType);
			sysParam.put("goods_color", goods_color);
			//public ServletContext application; baseAction中已经注入
			this.application.setAttribute("sysParam", sysParam);
		}
		
	}
	
}
页面获取map的jsp示例

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<%@ include file="/common/common.jsp"%>
<title>My JSP</title>
</head>
<body>

    <form id="ff" method="post">
       <div>
            <label for="supId">供应商编号:</label> <input type="text" name="supId" />
        </div>
        <div>
            <label for="supName">供应商:</label> <input type="text" name="supName" />
        </div>
        <div>
            <label for="supLinkman">联系人:</label> <input type="text"
                name="supLinkman" />
        </div>
        <div>
            <label for="supPhone">联系电话:</label> <input type="text"
                name="supPhone" />
        </div>
        <div>
            <label for="supAddress">联系地址:</label> <input type="text"
                name="supAddress" />
        </div>
                <div>
            <label for="supPay">期初应付:</label> <input type="text"
                name="supPay" />
        </div>
                <div>
            <label for="supType">供应商类型:</label>                                     
                <select id="cc" class="easyui-combobox" name="supType" style="width:200px;">   
                    <c:forEach items="${applicationScope.sysParam.supType}" var="supType">
                        <option value="${supType.key}">${supType.value}</option>   
                    </c:forEach>   
                </select>  
        </div>
        <div>
            <label for="supRemark">备注:</label>
            <textarea name="supRemark"></textarea>
        </div>
        <div>
            <input id="btn" type="button" value="提交" />
        </div>
    </form>

    <script type="text/javascript">
        $(function() {
            var win = parent.$("iframe[title='供应商管理']").get(0).contentWindow;//返回ifram页面文档(window)
        
            $("[name='supName']").validatebox({
                required : true,
                missingMessage : '请填写供应商!'
            });
            $("[name='supLinkman']").validatebox({
                required : true,
                missingMessage : '请填写出联系人!'
            });
            $("[name='supPhone']").validatebox({
                required : true,
                missingMessage : '请填写联系电话!'
            });
            //禁用验证
            $("#ff").form("disableValidation");

            $("#btn").click(function() {
                alert("ddddddddddd");
                $("#ff").form("enableValidation");
                if ($("#ff").form("validate")) {
                    alert("------------");
                    $('#ff').form('submit', {
                        url : '${proPath}/supplier/insert.action',
                        onSubmit : function() {
                            return true;
                        },
                        success : function(count) {                         
                            if(count>0){
                        	//可以定义为对应消息框
                                alert("成功");
                                parent.$("#win").window("close");
                                win.$("#dg").datagrid("reload");                            
                            } else{
                            	alert("添加失败!");
                            }  
                        }
                    });

                }

            });

        });
    </script>
</body>
</html>

用户词典表格设计

create table dictionary
(
   dic_id               int not null auto_increment,
    dic_field             varchar(20),
    dic_value          varchar(20),
    dic_text            varchar(11),
   primary key ( dic_id)
);




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值