×

springmvc常用标签

springmvc常用标签(在SpringMVC中 mvc:resources标签和resource标签有什么区别)

admin admin 发表于2024-09-27 18:34:31 浏览1 评论0

抢沙发发表评论

这篇文章给大家聊聊关于springmvc常用标签,以及在SpringMVC中 mvc:resources标签和resource标签有什么区别对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

本文目录

在SpringMVC中 mvc:resources标签和resource标签有什么区别

首先要导入spring相关包,poi,和fileupload包,我是使用maven构建的。 一.导入excel (1)使用spring上传文件a.前台页面提交《form name="excelImportForm" action="${pageContext.request.contextPath}/brand/importBrandSort" method="post" onsubmit="return checkImportPath();" enctype="multipart/form-data" id="excelImportForm"》《input type="hidden" name="ids" id="ids"》《div class="modal-body"》《div class="row gap"》《label class="col-sm-7 control-label"》《input class="btn btn-default" id="excel_file" type="file" name="filename" accept="xls"/》《/label》《div class="col-sm-3"》《input class="btn btn-primary" id="excel_button" type="submit" value="导入Excel"/》《/div》《/div》

巧用spring配置常量,该怎么解决

巧用spring配置常量巧用spring配置常量--常量也可以DI[/align有一些常量数据类型,比如货币,省份,转帐类型,等等。我们程序里都是用他们的代码进行运算的,但在页面显示的时候只能用他的名称显示给用户看。因此有下面特点:1有键值对,2不经常变化(支持偶尔有变化),3常用在页面做下拉选择,4在页面的时候此选择项又必须默认选中,5键值关系固定。碰到这种情况,有很多解决方法。比如可以在页面硬编码,把每个常量一一在页面写死,这样做的后果是代码很多,如果多个页面都包含此常量那么增加了维护的难度,另外一种是使用《fmt:messag/》+属性文件来处理,虽然有所改善,但不能使用《c:if》测试和比较。下面我推荐一种方法,希望能对大家有所帮助。实现步骤如下:1、 写一个公用工具类 ,所有的属性通过Spring启动时候注入public class MyConstantUtils { public static IBPConstantUtils obj; public IBPConstantUtils (String string) { obj = this; } /** * 货币类型 键值对 Spring启动的时候注入 */ public Map currTypes; public Map getCurrTypes() { return currTypes; } public void setCurrTypes(Map currTypes) { this.currTypes = currTypes; }//其他常量……}2、 配置文件web-xxx.xml,建议用一个单独的文件来配置常量。 《!-- 在配置文件中配置常量 --》 《bean id="currTypes" class="java.util.HashMap"》 《constructor-arg》 《map》 《entry key="USD"》 《value》美元《/value》 《/entry》 《entry key="HKD"》 《value》港元《/value》 《/entry》 《entry key="EUR"》 《value》欧元《/value》 《/entry》 《entry key="JPY"》 《value》日元《/value》 《/entry》 《entry key="AUD"》 《value》AUD《/value》 《/entry》 《entry key="RMB"》 《value》人民币《/value》 《/entry》 《/map》 《/constructor-arg》 《/bean》 《bean id="toolsUtils" class="com.xyz.util.MyConstantUtils "》 《constructor-arg》 《value》开始初始化工具类对象《/value》 《/constructor-arg》《!-- 将常量注入单例对象中 --》 《property name="currTypes"》 《ref bean="currTypes"/》 《/property》 《/bean》3、在jsp中,由于我们用的是springMVC,一般定义一个包含一些常用标签的jsp,如文件taglib.jsp:《!-- taglibs.jsp --》***隐藏网址******隐藏网址***《% request.setAttribute("MyConstantUtils",com.xyz.util.MyConstantUtils.obj); %》在上面的jsp中随便将我们的静态对象保存在request中,在其他jsp文件中include进来即可使用我们在配置文件中的常量,如下面:《%@include file="taglibs.jsp"%》………《tr align="center"》《td height="30" align="left"》《div align="right"》币种*《/div》《/td》《td width="78%" height="30" align="left"》《select name="currType"》《c:forEach items="${MyConstantUtils.currTypes}" var="currType"》《option value=’《c:out value="${currType.key}"/》’ 《c:if test=’${currType.key == "RMB"}’》selected《/c:if》》《c:outvalue="${currType.value}" /》《/option》

关于springmvc常用标签和在SpringMVC中 mvc:resources标签和resource标签有什么区别的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。