11. RestController注解

RestController注解

RestController注解可以直接返回一个对象,配合fastjson,可以将对象转换为json字符串返回给前端,适合ajax异步调用的场景,也是前后端分离中使用最频繁的开发方式!

pom.xml坐标


        com.alibaba
        fastjson
        1.2.28
        compile

springmvc.xml中的注解驱动


        
            
            
            
                
                    WriteMapNullValue
                    WriteDateUseDateFormat
                
            
        
    

Controller控制层的注解

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/test")
    public Map addGoodsToCartList(Long itemId, Integer num) {
           Map map = new HashMap();
           map.put("success", true);
           map.put("message", "welcome");
           return map;
    }
}

你可能感兴趣的:(11. RestController注解)