dbutils sqlserver 数据库 增加bigdecimal处理
4频完成:
1:增加类:
org.apache.commons.dbutils.handlers.columns.BigDecimalColumnHandler
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.dbutils.handlers.columns;
import org.apache.commons.dbutils.ColumnHandler;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Created by Administrator on 2/7/2018.
*/
public class BigDecimalColumnHandler implements ColumnHandler {
@Override
public boolean match(Class<?> propType) {
return propType.equals(java.math.BigDecimal.class);
}
@Override
public Object apply(ResultSet rs, int columnIndex) throws SQLException {
return Long.valueOf(rs.getBigDecimal(columnIndex).longValue());
}
}
2:增加类:
org.apache.commons.dbutils.handlers.properties.BigDecimalPropertyHandler
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.dbutils.handlers.properties;
import org.apache.commons.dbutils.PropertyHandler;
import java.math.BigDecimal;
import java.sql.Timestamp;
/**
* Created by Administrator on 2/7/2018.
*/
public class BigDecimalPropertyHandler implements PropertyHandler {
@Override
public boolean match(Class<?> parameter, Object value) {return parameter.equals(BigDecimal.class) && value instanceof java.lang.Long;
}
@Override
public Object apply(Class<?> parameter, Object value) {
return BigDecimal.valueOf(Long.parseLong(value.toString()));
}
}
3.修改配置文件org.apache.commons.dbutils.ColumnHandler
org.apache.commons.dbutils.handlers.columns.BigDecimalColumnHandler
4.
修改配置文件 org.apache.commons.dbutils.PropertyHandler
org.apache.commons.dbutils.handlers.properties.BigDecimalPropertyHandler
posted on 2018-02-08 08:42 mengzhaopeng 阅读(697) 评论(0) 收藏 举报
浙公网安备 33010602011771号