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) );