时间转换到前台页面,时间转换转换到后台代码

1:时间转换到前台页面

@Component
public class JsonDateSerializer extends JsonSerializer {

@Override
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
    jsonGenerator.writeString(DateUtil.format(date));
}

用上面的类操作 对应的实体类的属性类型是Date

@JsonSerialize(using = JsonDateSerializer.class)
public Date getModifydatetime() {

2:时间转换转换到后台代码

页面:<td><input class="easyui-datetimebox" name="endTime" /></td>

@Controller
@RequestMapping(“/testController”)
public class TestController extends BaseController{}

//1:name=“endTime"与params=“datagrid"一定不要一样啊,会出现无反应的效果

@RequestMapping(params="datagrid")
@ResponseBody
public EasyuiDataGridJson datagrid(EasyuiDataGrid gd,Users users){

//2:

@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    // binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
}

你可能感兴趣的:(时间转换到前台页面,时间转换转换到后台代码)