如何使用springboot验证器与freemarker?

时间:2018-05-23 02:47:10

标签: validation spring-boot freemarker

尝试使用带有freemarker的本机springboot验证程序来检查输入是否正确。 但是我的头版中出现了ftl错误。 代码如下: POJO

@Entity
@Table(name = "customer"/*, indexes = {@Index(name = "INX_CUSTOMER_NO", columnList = "no")}*/)
public class CustomerEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
Long id;
@Column(name = "name")
@NotBlank(message = "{notBlank}")
String name;

控制器

@RequestMapping(value = "/static/cust_add.html",method = {RequestMethod.GET,RequestMethod.POST})
public ModelAndView add(@Valid CustomerEntity cust, BindingResult bindingResult, RedirectAttributes redirectAttributes){
    ModelAndView mv = new ModelAndView();
    redirectAttributes.addFlashAttribute("cust", cust);
    mv.setViewName("/static/cust_add");
    return mv;
}

FTL

  <form action="/crm/static/cust_check.html" class="form-ajax-file">
    <table width="100%" border="0" align="center" cellpadding="4" cellspacing="4" bordercolor="#666666">
        <tr>
            <td colspan="2" bgcolor="#eeeeee">add customer info</td>
        </tr>
        <tr>
            <td width="150" align="right">customerName:</td>
            <td>
                <@spring.bind "cust.name"/>
                <input type="text" id="name" class="tr-width"/>
            </td>
            <td><@spring.showErrors ""/></td>
        </tr>
      </table>
    </form>

和错误

FreeMarker template error (DEBUG mode; use RETHROW in production!): The following has evaluated to null or missing: ==> spring [in template "static/cust_add.ftl" at line 20, column 19] ---- 

真的需要一些帮助

0 个答案:

没有答案