SpringMVC请求处理方法的返回值:
ModelAndView
Model
Map包含模型和属性
View
代表逻辑视图名的String
void
提供对Servlet的访问,以响应Http头部和内容的HttpEntity或ResponseEntity
Callable
DeferredResult
其他任意类型,Spring将其视作输出给View的对象模型
返回Json:
package com.fieldsignserver.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
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 org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
@Controller
@RequestMapping(value="/admin")
public class LoginController {
@ResponseBody
@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView login(@RequestParam("username") String username,@RequestParam("password") String password){
Map result = new HashMap<String,String>();
System.out.println("Username : "+username+", Password :"+password);
result.put("result", "success");
return new ModelAndView(new MappingJacksonJsonView(),result);
}
}