import java.util.*;
public class Test {
public static void main(String[] args) {
Map<String,String> map = new TreeMap<String,String>();
map.put("10", "America");
map.put("1", "Australia");
map.put("2", "India");
map.put("11", "China");
System.out.println(map);
}
}
Run Code Online (Sandbox Code Playgroud)
运行上面的代码片段时,在控制台中我得到的输出为:
{1=Australia, 10=America, 11=China, 2=India}
但我期待输出为
{1=Australia, 2=India, 10=America, 11=China}
但是当改变上面main()里面提到的逻辑时
Map<String,String> map = new TreeMap<String,String>();
map.put("US", "America");
map.put("AUS", "Australia");
map.put("IN", "India");
map.put("CH", "China");
System.out.println(map);
Run Code Online (Sandbox Code Playgroud)
我得到了理想的输出
({AUS=Australia, CH=China, IN=India, US=America})
根据我的理解,TreeMap的entrySet()方法返回映射中包含的映射的set视图.set的迭代器以升序键顺序返回映射.那么为什么会出现这种情况呢?
任何建议都非常感谢.
实际上我正在尝试将数据从jQuery发送到Spring控制器,而在Spring控制器中我试图使用自定义bean获取数据@RequestBody
.但我无法这样做.它不起作用.但是,当我发送相同的数据,因为@RequestParam
它工作正常,但万一@RequestBody
没有发生.我已经序列化了html表单并将该数据发布到控制器.我正在粘贴所有代码.我正在使用jQuery版本jquery-1.6.2.min.js
,下面是我正在使用的jar列表:
commons-fileupload-1.1.1.jar
commons-io-1.2.jar
commons-logging-1.1.1.jar
hibernate-validator-4.0.2.GA.jar
jackson-all-1.7.6.jar
jackson-mapper-asl-1.5.2.jar
jstl-1.2.jar
log4j-1.2.14.jar
servlet-2.3.jar
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
spring-asm-3.0.5.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-expression-3.0.5.RELEASE.jar
spring-tx-2.5.5.jar
spring-web-3.0.5.RELEASE.jar
spring-webmvc-3.0.5.RELEASE.jar
validation-api-1.0.0.GA.jar
Run Code Online (Sandbox Code Playgroud)
以下是控制器代码:
package com.devmanuals.tutorial.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.devmanuals.tutorial.service.ArithmeticService;
/**
* Handles and retrieves the main requests
*/
@Controller
@RequestMapping("/main/ajax")
public class AjaxController {
protected static Logger logger = Logger.getLogger("controller");
@Resource(name="springService")
private ArithmeticService …
Run Code Online (Sandbox Code Playgroud) 我需要在Java中检测操作系统名称和版本.我能做到的
String os_name = System.getProperty("os.name", "");
String os_version = System.getProperty("os.version", "");
Run Code Online (Sandbox Code Playgroud)
但问题是这不可靠.有时它返回不正确的信息,除了最流行的Windows,MacOS,Linux等,我无法检测到所有操作系统,这甚至在64位操作系统的情况下提供了错误的信息.我需要检测任何具有任何规格的操作系统.我无法找到合适的解决方案.
也许我可以用JavaScript做到这一点?如果在Java中不可能,请告诉我如何使用JavaScript.
任何意见或建议高度赞赏.
提前致谢.
最好的祝福,
**Nilanjan Chakraborty
什么是正则表达式,以确保给定的字符串包含至少一个来自以下每个字符的字符---
如何结合以上所有这些标准来验证字符串.