简体   繁体   中英

Spring MVC @ModelAttribute Case insensitive

I have the following method in my controller.

@RequestMapping(value = "/search", method = RequestMethod.GET)
public RedirectView search(@ModelAttribute DeepLinkUrl deepLinkUrl) {
  // method logic goes here
}

DeepLinkUrl POJO class

 public class DeepLinkUrl{
    private String promoCode;
  public String getPromoCode() {
    return promoCode;
}

public void setPromoCode(String promoCode) {
    this.promoCode = promoCode;
  }
}

URLS : /search?PromoCode=test /search?promoCode=test /search?promocode=test

Data binding is working only for the first two requests. I need to make this work case-insensitive.

您可以实现自己的不WebDataBinder大小写的BeanWrapper (用于WebDataBinder以便在使用@ModelAttribute时将参数从请求映射到Command Object的字段),或者将@RequestBody与json / xml格式的数据一起使用(推荐方式)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM