---
title: "当表单提交时将空字符串转换为null "
author: "hepx"
date: "2015-09-29T11:43:40Z"
tags: []
categories: ["开源软件"]
slug: "null"
draft: false
lastmod: "2015-09-29T11:43:40Z"
id: 2246708
url: "https://hepx.iteye.com/blog/2246708"
---

SpringMVC解决方案：

```
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
```

使用场景：比如做多条件查询时，hibernate的criteria需要过滤掉Form提交的空字符字段。