You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							46 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							46 lines
						
					
					
						
							1.4 KiB
						
					
					
				package com.ynxbd.wx.config;
 | 
						|
 | 
						|
import org.apache.commons.beanutils.converters.AbstractConverter;
 | 
						|
import org.apache.commons.lang3.StringUtils;
 | 
						|
 | 
						|
import java.time.LocalDateTime;
 | 
						|
import java.time.format.DateTimeFormatter;
 | 
						|
 | 
						|
public class MyLocalDateTimeConverter extends AbstractConverter {
 | 
						|
    private String timePattern = "yyyy-MM-dd HH:mm:ss";
 | 
						|
    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timePattern);
 | 
						|
 | 
						|
    public MyLocalDateTimeConverter() {
 | 
						|
        super();
 | 
						|
    }
 | 
						|
 | 
						|
    public MyLocalDateTimeConverter(String timePattern) {
 | 
						|
        super();
 | 
						|
        if (StringUtils.isNotBlank(timePattern) && !this.timePattern.equals(timePattern)) {
 | 
						|
            this.timePattern = timePattern;
 | 
						|
            dateTimeFormatter = DateTimeFormatter.ofPattern(timePattern);
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public MyLocalDateTimeConverter(Object defaultValue) {
 | 
						|
        super(defaultValue);
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    protected Class<?> getDefaultType() {
 | 
						|
        return LocalDateTime.class;
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
 | 
						|
        // We have to support Object, too, because this class is sometimes
 | 
						|
        // used for a standard to Object conversion
 | 
						|
        if (LocalDateTime.class.equals(type)) {
 | 
						|
 | 
						|
            return type.cast(LocalDateTime.parse(value.toString(), dateTimeFormatter));
 | 
						|
        }
 | 
						|
        throw conversionException(type, value);
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |