i have controller requestparam used. this
@requestmapping("/hello") public modelandview process(         @requestparam(value = "startdate",                        required = false,                        defaultvalue="yesterday()") startdate)   if startdate not specified defaultvalue used. in case value should dynamic e.g. now() or yesterday(). there way specify expression e.g. method of class return value?
i lazy use code everywhere
startdate=startdate!=null ? startdate : new date()   update ideally write custom expression provide e.g. start of current week or end of current month if date not specified
as explain here https://stackoverflow.com/a/22523299/636472:
you can handle case create behavior special word:
@initbinder public void initbinder(webdatabinder binder) throws exception {     final dateformat df = new simpledateformat("yyyy-mm-dd");     final customdateeditor dateeditor = new customdateeditor(df, true) {         @override         public void setastext(string text) throws illegalargumentexception {             if ("today".equals(text)) {                 setvalue(new date());             } else {                 super.setastext(text);             }         }     };     binder.registercustomeditor(date.class, dateeditor); }   @requestparam(required = false, defaultvalue = "today") date startdate      
Comments
Post a Comment