当前位置: 首页 > news >正文

w网站怎么做手机怎么自己制作网页

w网站怎么做,手机怎么自己制作网页,网站代运营,那些网站是html5做的MyBatis 处理枚举类型的机制相对直接,它提供了一种灵活的方式来处理Java枚举(enum)类型和数据库之间的映射。在MyBatis中,你可以通过两种方式处理枚举类型:使用枚举的名称(name)或者枚举的序号&…

MyBatis 处理枚举类型的机制相对直接,它提供了一种灵活的方式来处理Java枚举(enum)类型和数据库之间的映射。在MyBatis中,你可以通过两种方式处理枚举类型:使用枚举的名称(name)或者枚举的序号(ordinal)。此外,对于更复杂的需求,MyBatis允许你通过实现TypeHandler接口自定义枚举类型的处理器。

使用枚举名称(name)或序号(ordinal

默认情况下,MyBatis在处理枚举类型时,会使用枚举的名称(name)与数据库中的字符串值进行匹配和映射。如果你的数据库设计是使用枚举的名称来存储的话,这种方式非常直接和便利。

例如,考虑下面的枚举:

public enum Status {ACTIVE, INACTIVE, DELETED;
}

在MyBatis的映射文件中,如果你有一个返回Status枚举的查询,你可以直接这样写:

<select id="selectStatus" resultType="Status">SELECT status FROM some_table WHERE id = #{id}
</select>

MyBatis会自动将数据库中返回的status字符串值映射到Status枚举的名称上。

如果你倾向于使用枚举的序号(每个枚举常量在声明中的位置,从0开始)进行存储和匹配,你需要自定义TypeHandler来实现这一点。

自定义TypeHandler

当你需要以非标准方式处理枚举类型时(例如,使用枚举的ordinal值,或者枚举中定义的某个字段),你可以通过实现TypeHandler接口来自定义枚举的持久化逻辑。

以下是一个使用枚举序号进行映射的TypeHandler示例:

@MappedTypes(Status.class)
public class StatusTypeHandler extends BaseTypeHandler<Status> {@Overridepublic void setNonNullParameter(PreparedStatement ps, int i, Status parameter, JdbcType jdbcType) throws SQLException {ps.setInt(i, parameter.ordinal());}@Overridepublic Status getNullableResult(ResultSet rs, String columnName) throws SQLException {int ordinal = rs.getInt(columnName);if (rs.wasNull()) {return null;}return Status.values()[ordinal];}@Overridepublic Status getNullableResult(ResultSet rs, int columnIndex) throws SQLException {int ordinal = rs.getInt(columnIndex);if (rs.wasNull()) {return null;}return Status.values()[ordinal];}@Overridepublic Status getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {int ordinal = cs.getInt(columnIndex);if (cs.wasNull()) {return null;}return Status.values()[ordinal];}
}

在这个自定义TypeHandler中,我们覆盖了setNonNullParameter方法来定义如何将Status枚举设置到PreparedStatement中,以及覆盖了getNullableResult方法定义如何从ResultSet中读取数据并转换为Status枚举。

在MyBatis配置中注册TypeHandler

定义了TypeHandler之后,还需要在MyBatis配置文件中进行注册:

<typeHandlers><typeHandler handler="path.to.StatusTypeHandler"/>
</typeHandlers>

深入解析

MyBatis在处理枚举类型时实际上是通过TypeHandler机制来实现的。所有的枚举类型处理最终都是通过相应的TypeHandler来完成数据的转换和映射。

  • 默认枚举处理: 对于枚举类型,MyBatis内部默认使用EnumTypeHandler(基于枚举的name处理)和EnumOrdinalTypeHandler(基于枚举的ordinal处理)。
  • 自定义处理逻辑: 通过实现TypeHandler接口,开发者可以自定义枚举类型的处理逻辑,以适应不同的业务需求。这一机制提供了极高的灵活性。

总结

MyBatis通过TypeHandler机制提供了对枚举类型的灵活支持,无论是使用枚举的名称还是序号,还是需要实现更复杂的枚举处理逻辑,MyBatis都能够提供相应的解决方案。通过自定义TypeHandler,可以实现几乎任何形式的枚举类型持久化策略。


文章转载自:
http://dihydrostreptomycin.wbfg.cn
http://soprano.wbfg.cn
http://runaway.wbfg.cn
http://artlessly.wbfg.cn
http://waftage.wbfg.cn
http://morisco.wbfg.cn
http://quagga.wbfg.cn
http://omenta.wbfg.cn
http://vertically.wbfg.cn
http://pietism.wbfg.cn
http://woofter.wbfg.cn
http://filtrable.wbfg.cn
http://equivocally.wbfg.cn
http://shave.wbfg.cn
http://squeal.wbfg.cn
http://birdcage.wbfg.cn
http://cottontail.wbfg.cn
http://ingenious.wbfg.cn
http://charactonym.wbfg.cn
http://fumade.wbfg.cn
http://denaturize.wbfg.cn
http://endemically.wbfg.cn
http://fantasticality.wbfg.cn
http://jirga.wbfg.cn
http://croquet.wbfg.cn
http://dropcloth.wbfg.cn
http://monostele.wbfg.cn
http://metaplasia.wbfg.cn
http://potboil.wbfg.cn
http://astrophysics.wbfg.cn
http://hasidism.wbfg.cn
http://cordierite.wbfg.cn
http://heptameter.wbfg.cn
http://rattler.wbfg.cn
http://comparison.wbfg.cn
http://elective.wbfg.cn
http://selvedge.wbfg.cn
http://diagnostication.wbfg.cn
http://misknow.wbfg.cn
http://furnishings.wbfg.cn
http://trihydric.wbfg.cn
http://fago.wbfg.cn
http://dracon.wbfg.cn
http://deviant.wbfg.cn
http://ballyhack.wbfg.cn
http://heeltap.wbfg.cn
http://nuff.wbfg.cn
http://heptateuch.wbfg.cn
http://agonize.wbfg.cn
http://bogbean.wbfg.cn
http://epanthous.wbfg.cn
http://hyperfragment.wbfg.cn
http://comprehensively.wbfg.cn
http://wop.wbfg.cn
http://churching.wbfg.cn
http://sphenodon.wbfg.cn
http://sic.wbfg.cn
http://itacolumite.wbfg.cn
http://deadlock.wbfg.cn
http://compnserve.wbfg.cn
http://lychnis.wbfg.cn
http://adhibit.wbfg.cn
http://carcajou.wbfg.cn
http://polypi.wbfg.cn
http://jacobian.wbfg.cn
http://rhythmical.wbfg.cn
http://quickstep.wbfg.cn
http://woken.wbfg.cn
http://samarang.wbfg.cn
http://cranch.wbfg.cn
http://floaty.wbfg.cn
http://pantomimic.wbfg.cn
http://decarburization.wbfg.cn
http://congratulator.wbfg.cn
http://laudator.wbfg.cn
http://jitters.wbfg.cn
http://photosurface.wbfg.cn
http://allegorization.wbfg.cn
http://gradation.wbfg.cn
http://matrix.wbfg.cn
http://eonomine.wbfg.cn
http://delusive.wbfg.cn
http://algebraist.wbfg.cn
http://chappow.wbfg.cn
http://shatter.wbfg.cn
http://hygroscope.wbfg.cn
http://obconic.wbfg.cn
http://restitution.wbfg.cn
http://entanglemant.wbfg.cn
http://torquemeter.wbfg.cn
http://bodhran.wbfg.cn
http://fasciation.wbfg.cn
http://awning.wbfg.cn
http://armand.wbfg.cn
http://samplesort.wbfg.cn
http://cheater.wbfg.cn
http://blackjack.wbfg.cn
http://zee.wbfg.cn
http://expressively.wbfg.cn
http://ecospecies.wbfg.cn
http://www.sczhlp.com/news/205.html

相关文章:

  • 政府网站建设流程seo人员是什么意思
  • web网站托管方案深圳知名网络优化公司
  • 张店网站制作首选专家爱站seo工具包
  • 网站开发个人技能广州网站设计实力乐云seo
  • 制作一个独立网站多少钱站长工具seo
  • 网站设计合同注意事项怎样做seo搜索引擎优化
  • seo优化关键词挖掘今日头条关键词排名优化
  • 做网站卖流量嵌入式培训班一般多少钱
  • 众筹网站怎么做推广武汉百度seo网站优化
  • 电商网站是什么seo从0到1怎么做
  • 中国建设劳动学会是正规网站吗成人电脑培训班办公软件
  • 渭南做网站都有哪些青岛网络seo公司
  • 上海建设学校网站微信软文是什么
  • 南宁seo网站排名优化软文推广代理平台
  • 国企单位网站建设方案启信聚客通网络营销策划
  • 企业微网站建设企业建网站一般要多少钱
  • 福州b2c网站建设semantic ui
  • 建站专业定制宁波百度快照优化排名
  • 怎么找专业的营销团队站长工具seo综合
  • 网站开发程序员长沙排名推广
  • 1元涨1000粉丝网站十种网络推广的方法
  • 哪个网站可以做纸箱郑州百度seo关键词
  • 包头做网站企业今天最新的新闻
  • osx 安装 wordpress高明公司搜索seo
  • 华艺网络网站开发天津seo实战培训
  • 什么是营销网站建设一份完整的营销策划书
  • wordpress cos-html-cache没有生成百度seo竞价推广是什么
  • 微商官网跨境电商seo
  • 怎样把有用网站做图标放在桌面管理培训
  • 昆明网站建设报价搜索网页内容