zoukankan      html  css  js  c++  java
  • spring mvc后台如何处理ajax的请求,并返回json

    spring mvc中有一个注解:@ResponseBody,把这个注解放到ajax请求对应的@RequestMapping(xxx)方法上,在方法体内部,把要返回的json赋给一个String类型的变量,然后return这个变量即可,例子如下:

            @ResponseBody  
        @RequestMapping("/show")
        public String show(Map<String,Object> map,String username){
            System.out.println("----enter show method");
            RepositoryService rs = processEngine.getRepositoryService();
            ExecutionService es = processEngine.getExecutionService();
            TaskService ts = processEngine.getTaskService();
            List<ProcessDefinition> liststemp = rs.createProcessDefinitionQuery().list();
            List<PD> lists=toJsonList.processDefine2PD(liststemp)
            Gson gson=new Gson();
            String str=gson.toJson(lists);
            
            return str;
    @ResponseBody  
    	@RequestMapping("/show")
    	public String show(Map<String,Object> map,String username){
    		System.out.println("----enter show method");
    		RepositoryService rs = processEngine.getRepositoryService();
    		ExecutionService es = processEngine.getExecutionService();
    		TaskService ts = processEngine.getTaskService();
    		List<ProcessDefinition> liststemp = rs.createProcessDefinitionQuery().list();
    		List<PD> lists=toJsonList.processDefine2PD(liststemp)
    		Gson gson=new Gson();
    		String str=gson.toJson(lists);
    		
    		return str;
    

      

     

  • 相关阅读:
    命令[46]
    命令[53]
    命令[48]
    命令[43]
    命令[52]
    命令[55]
    命令[41]
    MYSQL[02]大小写问题
    hdu 1811
    hdu 1829
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/5590927.html
Copyright © 2011-2022 走看看