1. 程式人生 > >Spring中註解

Spring中註解

name return resource 處理 ransac ack json attr servlet

@Autowired :spring註解

@Resource :J2EE註解

@Transactional(rollbackFor=Exception.class):指定回滾

@RequestMapping(value="/device/snap/{deviceCode}/{channelId}",method=RequestMethod.POST)

public @ResponseBody void snap(@PathVariable String deviceCode,@PathVariable String channelId, HttpServletRequest request, HttpServletResponse response)

[email protected]的對象通過適當的轉換器轉換為指定的格式之後,寫入到response對象的body區,通常用來返回JSON數據或者是XML

  數據,需要註意的呢,在使用此註解之後不會再走試圖處理器,而是直接將數據寫入到輸入流中,他的效果等同於通過response對象輸出指定格式的數據。  

[email protected]("/login")
[email protected]
  public User login(User user){
    return user;
  }
  User字段:userName pwd
  那麽在前臺接收到的數據為:‘{"userName":"xxx","pwd":"xxx"}‘

  效果等同於如下代碼:
[email protected]

/* */("/login")
  public void login(User user, HttpServletResponse response){
    response.getWriter.write(JSONObject.fromObject(user).toString());
  }

public void sendProduct(@RequestParam int productId) @RequestParam:獲取請求參數

public String submitOrder(@ModelAttribute Order order, Model model) @ModelAttribute:使用鍵值order將Order實例添加到Model對象中

Spring中註解