ModelMap的作用
来源:互联网 发布:python spawn 编辑:程序博客网 时间:2024/06/06 10:04
最近在用ssm框架开发项目,之前都是二次开发,现在是从头开发,都有点不适应了,遇到了很多前端后台的问题。
说说ModelMap的作用
package org.springframework.ui;import java.util.Collection;import java.util.LinkedHashMap;import java.util.Map;import org.springframework.core.Conventions;import org.springframework.util.Assert;@SuppressWarnings("serial")public class ModelMap extends LinkedHashMap<String, Object> {public ModelMap() {}public ModelMap(String attributeName, Object attributeValue) {addAttribute(attributeName, attributeValue);}public ModelMap(Object attributeValue) {addAttribute(attributeValue);}public ModelMap addAttribute(String attributeName, Object attributeValue) {Assert.notNull(attributeName, "Model attribute name must not be null");put(attributeName, attributeValue);return this;}public ModelMap addAttribute(Object attributeValue) {Assert.notNull(attributeValue, "Model object must not be null");if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {return this;}return addAttribute(Conventions.getVariableName(attributeValue), attributeValue);}public ModelMap addAllAttributes(Collection<?> attributeValues) {if (attributeValues != null) {for (Object attributeValue : attributeValues) {addAttribute(attributeValue);}}return this;}public ModelMap addAllAttributes(Map<String, ?> attributes) {if (attributes != null) {putAll(attributes);}return this;}public ModelMap mergeAttributes(Map<String, ?> attributes) {if (attributes != null) {for (Map.Entry<String, ?> entry : attributes.entrySet()) {String key = entry.getKey();if (!containsKey(key)) {put(key, entry.getValue());}}}return this;}public boolean containsAttribute(String attributeName) {return containsKey(attributeName);}}代码里面有个方法:addAttribute和addAttributeAll
这个方法其实就是我们经常用的,在代码里面一般是这样体现的:
map.put("smallGoods", smallGoods);
就是把后台查询出来的集合、字符串(一般是错误信息)、对象等传到前台,当然,这个值不能是空的
前台接收参数时:两个问号是判断这个对象或者集合是否为空
<#if smallGoods??><#list smallGoods as specialControl><option id="${specialControl.goodstypeid}" name="tempgoodstypeid" value="${specialControl.goodstypeid}">${specialControl.goodsdesc}</option></#list><#else></#if>
阅读全文
1 0
- ModelMap的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和@SessionAttributes的作用
- ModelMap和ModelAttribute的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- ModelMap和ModelAndView的作用
- Android移动开发-如何在AndroidStudio里进行对应用程序进行签名
- JavaWeb之Maven
- 将oracle的dmp导入到不同表空间 oracle的dmp文件导入到不同表空间 oracle将dmp文件导入到不同的表空间方法: 1、exp USER/PASSOWRD@SID file=c:\t
- 提高代码可读性的 10 个技巧
- 直播架构-问题记录
- ModelMap的作用
- BM算法
- XListView使用
- 使用jQuery中prependTo appendTo图片轮播凸出效果
- MindManager 2018如何新建维恩图
- 你知道Guitar Pro 7可以编辑中文歌词吗?
- 消费者与生产者
- hibernate.hbm2ddl.auto四种取值
- java求0—7所能组成的奇数个数。