‘壹’ Map接口的putAll()方法如何使用
import Java.util.HashMap;
public class Map_putAllTest {
public static void main(String[] args){
//两个map具有不同的key
HashMap map1=new HashMap();
map1.put("1", "A");
HashMap map2 = new HashMap();
map2.put("2", "B");
map2.put("3", "C");
map1.putAll(map2);
System.out.println(map1);
//两个map具有重复的key
HashMap map3=new HashMap();
map3.put("1", "A");
HashMap map4 = new HashMap();
map4.put("1", "B");
map4.put("3", "C");
map3.putAll(map4);
System.out.println(map3);
}
}
/* 输出结果:
* {3=C, 2=B, 1=A}
* {3=C, 1=B}
* 结论:putAll可以合并两个MAP,只不过如果有相同的key那么用后面的覆盖前面的
* */
复制的,不过写的不错,也直观
‘贰’ resttemplate远程接口调用 传一个map 怎么调用map参数
spring rest mvc使用RestTemplate远程接口调用
主要代码如下:
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.client.RestTemplate;
‘叁’ 微信web前端开发,调用设备相机和相册的接口怎么用
********************后台接口代码**********************
StringaccessJsapiTicket=AccessJsapiTicketBLL.getAccessJsapiTicket();
Stringnoncestr=StringUtils.genNoncestr(15);
longtimestamp=System.currentTimeMillis()/1000;
Stringsignature=SignatureFactory.sign(accessJsapiTicket,noncestr,timestamp,url);
Map<String,String>map=newHashMap<String,String>();
map.put("timestamp",""+timestamp);
map.put("nonceStr",noncestr);
map.put("signature",signature);
map.put("id",ManageKeyUtils.getValueByKey("wx_mp_app_id"));
returnwriter().write(JackSonTool.parse2Json(map));---------------------------------------------------------------publicstaticStringsign(Stringjsapi_ticket,Stringnoncestr,longtimestamp,Stringurl){
Strings="jsapi_ticket="+jsapi_ticket
+"&noncestr="+noncestr
+"×tamp="+timestamp
+"&url="+url;
returnSHA1.crypt(s);
}-----------------------------------------------------------------publicstaticStringcrypt(Stringstr){
byte[]inputData=str.getBytes();
StringreturnString="";
try{
MessageDigestsha=MessageDigest.getInstance("SHA");
sha.update(inputData);
returnString=byte2hex(sha.digest());
}catch(Exceptione){
e.printStackTrace();
}
returnreturnString;
}
privatestaticStringbyte2hex(bytebytes[]){
StringBufferretString=newStringBuffer();
for(inti=0;i<bytes.length;++i){
retString.append(Integer.toHexString(0x0100+(bytes[i]&0x00FF)).substring(1));
}
returnretString.toString();
}
******************页面js代码**************varmap=$!map;//从后台获取这几个对象
wx.config({
debug:false,//调试阶段建议开启
appId:map.id,
timestamp:map.timestamp,
nonceStr:map.nonceStr,
signature:map.signature,
jsApiList:[
/**所有要调用的API都要加到这个列表中*这里以图像接口为例*/
"chooseImage",
"previewImage",
"uploadImage",
"downloadImage"
]
});
//定义images用来保存选择的本地图片ID,和上传后的服务器图片ID
varimages={
localId:[],
serverId:[]
};
wx.ready(function(){
//拍照、本地选图
document.querySelector('.enroll_img').onclick=function(){
wx.chooseImage({
success:function(result){
//dosomething
}
});
}
})
‘肆’ 前端调用接口404报错
今天遇到了一个很离奇的场景,使用ajax请求后台结果 后台处理成功了页面还报了404错误。
程序员不说话,默默上代码:
JS:
[javascript] view plain  
var save = function(){
$.ajax({
url: urlMap.saveOrUpdateGroupInfo,
type: 'post',
async: false,
dataType: 'json',
data: $("#groupInfo").serialize()
}).done(function(res) {
console.log(res);
if(res.success) {
}else{
bootbox.alert(res.msg);
}
});  
}  
后端:
[java] view plain 
@RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
public ResponseVo saveOrUpdate(String id, String name, String parentId, String parentName, String operate){
ResponseVo result = new ResponseVo();
GroupInfo info = new GroupInfo();
Date now =new Date();
info.setUpdateTime(now);
try{
if(operate.equals("add")){
info.setParentId(Integer.parseInt(parentId));
info.setName(name);
info.setCreateTime(now);
groupInfoService.addGroup(info);
}else if (operate.equals("edit")) {
info.setId(Integer.parseInt(id));
info.setName(name);
info.setParentId(Integer.parseInt(parentId));
groupInfoService.updateGroup(info);
}else if (operate.equals("delete")) {
groupInfoService.deleteGroup(Integer.parseInt(id));
}
result.setSuccess(true);
}catch (Exception e){
log.error("operate group error."+ JsonUtil.toString(info), e);
result.setSuccess(false);
result.setMsg(e.getMessage());
}
return result;
}  
}  
挺奇怪吧?
经分析是请求没有返回状态码,这是因为我用的是SpringMVC框架,前后端使用JSON传递数据,因为返回的是对象,而忘记了添加
@ResponseBody
注解,所以 Spring对我的返回值进行了映射,但是映射结果又对应不到视图,所以返回了404
正常后台代码:
[java] view plain  
@RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
@ResponseBody
public ResponseVo saveOrUpdate(String id, String name, String parentId, String parentName, String operate){
ResponseVo result = new ResponseVo();
GroupInfo info = new GroupInfo();
Date now =new Date();
info.setUpdateTime(now);
try{
if(operate.equals("add")){
info.setParentId(Integer.parseInt(parentId));
info.setName(name);
info.setCreateTime(now);
groupInfoService.addGroup(info);
}else if (operate.equals("edit")) {
info.setId(Integer.parseInt(id));
info.setName(name);
info.setParentId(Integer.parseInt(parentId));
groupInfoService.updateGroup(info);
}else if (operate.equals("delete")) {
groupInfoService.deleteGroup(Integer.parseInt(id));
}
result.setSuccess(true);
}catch (Exception e){
log.error("operate group error."+ JsonUtil.toString(info), e);
result.setSuccess(false);
result.setMsg(e.getMessage());
}
return result;
}
‘伍’ map怎么调用 callout
点击泡泡会调用 #pragma mark -当点击annotation view弹出的泡泡时,调用此接口 - (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view{ NSLog(@"paopaoclick"); }
‘陆’ 关于Map接口方法示例的疑惑
你的代码有3处错误,个人认为都是马虎错。
1、String的首字母应该大些,而不是string
2、Integer类而不是interger
3、最后面的System.out.println(m.size()+ “distinct words:”);请你用英文的""而不是中文的“”
‘柒’ java map接口怎么用啊
使用注意:对于Map的使用,初始化应注意!
将Map装载进List当中,虽然循环多次赋值,并且每次赋值后的Map装载入List,但实际到最后时,List中所有的Map为同一键值,因此建议在循环内每次都New一个新的Map对象,但为了效率考虑,最好就Map的申明放在循环外做;
public List readExcel(String fileUrl, String fileName, int sheetNum,
    String[] attribute, int startRow, int[] ignoreColumn) {
   // 返回值
   List<Map<String, String>> result = new ArrayList<Map<String, String>>();
   // 文件流
   InputStream is = null;
   // 读入文档的出错行号
   int errorRow = 0;
   try {
    // 如果同一文档,则只产生一个实例
    if (wb == null) {
     is = new FileInputStream(fileUrl + "\\" + fileName);
     wb = Workbook.getWorkbook(is);
     is.close();
    }
    // 读入Sheet页
    Sheet sheet = wb.getSheet(sheetNum);
    // 行数
    int rows = sheet.getRows();
    // 根据每个Sheet页的字段数指定列数
    int columns = attribute.length - 1 + ignoreColumn.length;
    int countAttribute = 0;
    // 打印信息
    // System.out.print(sheet.getName() + " ");
    // System.out.print("rows:" + rows);
    // System.out.println(" columns" + columns);
    // 逐行读入
   // Map<String, String> map = new HashMap<String, String>();
    Map<String, String> map;
    boolean rowIsNull;
    aaa: for (int i = startRow - 1; i < rows; i++) {
     // 每次读入文档前,清空map
    // map.clear();
     map = new HashMap<String, String>();
     // 当前Sheet页行数(指Excel行号)
     errorRow = i + 1;
     // 不为空列数计数值
     int columnIsNotNullNum = 0;
     // 一行数据中,必须有至少5列以上的数据,才认为该行为正常数据,否则退出
     rowIsNull = true;
     for (int k = 0; k < columns; k++) {
      String rowContent = sheet.getCell(k, i).getContents();
      if (rowContent != null && !rowContent.equals("")) {
       ++columnIsNotNullNum;
      }
      if (columnIsNotNullNum >= 5) {
       rowIsNull = false;
       break;
      }
     }
     // 如果一行不超过5列有值,则跳出循环
     if (rowIsNull)
      break aaa;
     // 逐列读值
     bbb: for (int j = 0; j < columns; j++) {
      for (int k = 0; k < ignoreColumn.length; k++)
       // 不读忽略的列
       if (j == ignoreColumn[k] - 1)
        continue bbb;
      // 取得单元格内容
      String sbcContent = sheet.getCell(j, i).getContents();
      // 全角转换为半角
      String content = CommonUtil.sbcChange(sbcContent);
      // 建立数据库字段键值映射关系
      map.put(attribute[countAttribute], content.trim());
      countAttribute++;
     }
     // 将文档名称入库
     map.put(attribute[countAttribute], fileName);
     result.add(map);
     countAttribute = 0;
    }
   } catch (Exception e) {
    wb.close();
    try {
     is.close();
    } catch (IOException e1) {
     e1.printStackTrace();
    }
    e.printStackTrace();
    result = null;
    System.out.println(CommonCode.ERR_READ_ROW + ":" + errorRow);
   }
   return result;
}
‘捌’ Map接口继承了哪个类或实现了哪个接口
乱回答的真恶心,只会复制拷贝了么。首先Map接口已经是最底层的接口,没有继承了哪个类,而是被HashMap、TreeMap、SortedMap等实现类所实现。而List和Set接口都是继承Collection接口,然后Collection接口又继承迭代器Iterator接口。虽然map可以迭代,但是记住它不继承collection接口,更加不可能继承迭代器
‘玖’ java Map接口
importjava.util.*;
publicclassStudent{
privateStringa;
privateStringb;
privateStringc;
publicStudent(Stringa,Stringb,Stringc){
this.a=a;
this.b=b;
this.c=c;
}
publicvoidtoString(){
System.format("%1$2s%2$2s%3$2s",a,b,c);
}
publicstaticvoidmain(String[]args){
Studenta=newStudent("张三","李四","王五");
Studentb=newStudent("郭靖","黄蓉","杨过");
Studentc=newStudent("鸡","狗","猪");
ArrayList<Student>list=newArrayList<Student>();
list.add(a);
list.add(b);
list.add(c);
HashMap<String,Student>banji=newHashMap<String,Student>();
banji.put("三年级一班",a);
banji.put("三年级二班",b);
banji.put("三年级三班",c);
Scannerscan=newScanner(System.in);
while(true){
Stringline=scan.nextLine().trim();
if(map.containsKey(line)){
map.get(line).toString();
}else{
System.err.println("nothing...");
scan.close();
break;
}
}
}
}
‘拾’ Map接口都有哪些方法
void clear() 
          从此映射中移除所有映射关系(可选操作)。 
 boolean containsKey(Object key) 
          如果此映射包含指定键的映射关系,则返回 true。 
 boolean containsValue(Object value) 
          如果此映射为指定值映射一个或多个键,则返回 true。 
 Set<Map.Entry<K,V>> entrySet() 
          返回此映射中包含的映射关系的 set 视图。 
 boolean equals(Object o) 
          比较指定的对象与此映射是否相等。 
 V get(Object key) 
          返回此映射中映射到指定键的值。 
 int hashCode() 
          返回此映射的哈希码值。 
 boolean isEmpty() 
          如果此映射未包含键-值映射关系,则返回 true。 
 Set<K> keySet() 
          返回此映射中包含的键的 set 视图。 
 V put(K key, V value) 
          将指定的值与此映射中的指定键相关联(可选操作)。 
 void putAll(Map<? extends K,? extends V> t) 
          从指定映射中将所有映射关系复制到此映射中(可选操作)。 
 V remove(Object key) 
          如果存在此键的映射关系,则将其从映射中移除(可选操作)。 
 int size() 
          返回此映射中的键-值映射关系数。 
 Collection<V> values() 
          返回此映射中包含的值的 collection 视图。 
打开API查看就都知道了
