All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.vonce.sql.spring.mapper.SpringJdbcSqlBeanMapper Maven / Gradle / Ivy

Go to download

This is a tool that uses java object-oriented idea to write and generate SQL statements. On this basis, it also implements lightweight plug-in support similar to JPA for mybatis and spring JDBC. A large number of common SQL execution methods are built in plug-ins to improve development efficiency, reduce a large number of SQL statement writing, and make developers focus on business code writing.

The newest version!
package cn.vonce.sql.spring.mapper;

import cn.vonce.sql.mapper.ResultSetDelegate;
import cn.vonce.sql.mapper.SqlBeanMapper;
import cn.vonce.sql.uitls.SqlBeanUtil;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;

/**
 * Spring jdbc 结果映射
 *
 * @author Jovi
 * @version 1.0
 * @email [email protected]
 */
public class SpringJdbcSqlBeanMapper extends SqlBeanMapper implements RowMapper {

    public Class clazz;
    public Class returnType;

    public SpringJdbcSqlBeanMapper(Class clazz, Class returnType) {
        this.clazz = clazz;
        this.returnType = returnType;
    }

    @Override
    public T mapRow(ResultSet resultSet, int index) {
        ResultSetDelegate resultSetDelegate = new ResultSetDelegate<>(resultSet);
        Object value;
        if (SqlBeanUtil.isMap(returnType)) {
            value = super.mapHandleResultSet(resultSetDelegate);
        } else if (!SqlBeanUtil.isBaseType(returnType)) {
            value = super.beanHandleResultSet(returnType, resultSetDelegate, super.getColumnNameList(resultSetDelegate));
        } else {
            value = super.baseHandleResultSet(resultSetDelegate);
            if (value != null && value.getClass() != returnType) {
                value = SqlBeanUtil.getValueConvert(returnType, value);
            }
        }
        return (T) value;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy