Giter Club home page Giter Club logo

Comments (2)

miemieYaho avatar miemieYaho commented on June 19, 2024

没有

from mybatis-plus.

cnscud avatar cnscud commented on June 19, 2024

研究了一下, 使用一个定制的typeHandler可以实现:

/**

  • Type Handler for like "Status" Enum String field.

  • @author Felix Zhang 2024-05-06 10:30

  • @Version 1.0.0
    */
    @MappedJdbcTypes({JdbcType.OTHER})
    @MappedTypes({String.class})
    @slf4j
    public class StringEnumTypeHandler extends BaseTypeHandler {

    @OverRide
    public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException {
    log.info("String: " + parameter);
    ps.setString(i, parameter);
    }

    @OverRide
    public T getNullableResult(ResultSet rs, String columnName) throws SQLException {
    log.info("value: " + rs.getString(columnName));
    return (T) rs.getString(columnName);
    }

    @OverRide
    public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
    return (T) rs.getString(columnIndex);
    }

    @OverRide
    public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    return (T) cs.getString(columnIndex);
    }

}

然后在mybatis配置里配置 type-handlers-package 为你的包名

然后Java里使用String类型, Jdbc类型就用Other就可以.

Java里也可以用 Integer, 不过就要另外写一个typeHandler了.

from mybatis-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.