<commit_before>---
layout: post
title: SpringMVC-参数绑定方式
author: leping
category: Pages
tags: [jekyll, github]
---

## @Requestparam 绑定单个请求的值
  **
   url：/requestparam1?username=zhang
   @RequestMapping("/requestparam1")
   public String requestparam2(@RequestParam("username") String username) 
   **
## @PathVariable 绑定URI模板变量值

  **
  @RequestMapping(value="/users/{userId}/topics/{topicId}")  
  public String test(  
       @PathVariable(value="userId") int userId,   
       @PathVariable(value="topicId") int topicId)
  **

## @SessionAttributes 绑定命令对象到session
   **
   //1、在控制器类头上添加@SessionAttributes注解  
   @SessionAttributes(value = {"user"})    
   public class SessionAttributeController   
  
   //2、@ModelAttribute注解的方法进行表单引用对象的创建  
   @ModelAttribute("user")    
   public UserModel initUser()   
  
   //3、@RequestMapping注解方法的@ModelAttribute注解的参数进行命令对象的绑定  
   @RequestMapping("/session1")   
   public String session1(@ModelAttribute("user") UserModel user)  
  
   //4、通过SessionStatus的setComplete()方法清除@SessionAttributes指定的会话数据  
   @RequestMapping("/session2")   
   public String session(@ModelAttribute("user") UserModel user, SessionStatus status) {  
    if(true) { //④  
        status.setComplete();  
    }  
    return "success";  
    }
    **
  
## @Value 绑定从配置文件取值
<commit_msg>Update 2016-05-30-SpringMVC-参数绑定方式.md<commit_after>---
layout: post
title: SpringMVC-参数绑定方式
author: leping
category: Pages
tags: [jekyll, github]
---

## @Requestparam 绑定单个请求的值
 
   url：/requestparam1?username=zhang  
   @RequestMapping("/requestparam1")  
   public String requestparam2(@RequestParam("username") String username)  
 
## @PathVariable 绑定URI模板变量值

  @RequestMapping(value="/users/{userId}/topics/{topicId}")   
  public String test(  
       @PathVariable(value="userId") int userId,   
       @PathVariable(value="topicId") int topicId)  


## @SessionAttributes 绑定命令对象到session
   //1、在控制器类头上添加@SessionAttributes注解  
   @SessionAttributes(value = {"user"})    
   public class SessionAttributeController   
  
   //2、@ModelAttribute注解的方法进行表单引用对象的创建  
   @ModelAttribute("user")    
   public UserModel initUser()   
  
   //3、@RequestMapping注解方法的@ModelAttribute注解的参数进行命令对象的绑定  
   @RequestMapping("/session1")  
   public String session1(@ModelAttribute("user") UserModel user)  
  
   //4、通过SessionStatus的setComplete()方法清除@SessionAttributes指定的会话数据  
   @RequestMapping("/session2")   
   public String session(@ModelAttribute("user") UserModel user, SessionStatus status) {  
    if(true) { //④   
        status.setComplete();    
    }    
    return "success";  
    }  

  
## @Value 绑定从配置文件取值  

{'fraction_non_alphanumeric': 0.12233231707317073, 'fraction_numerical': 0.010670731707317074, 'mean_word_length': 3.679144385026738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6881797', 'n_tokens_mistral': 944, 'n_tokens_neox': 960, 'n_words': 139}