当前位置: 首页 > 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://ghoul.dbfp.cn
http://ringleader.dbfp.cn
http://gangdom.dbfp.cn
http://micron.dbfp.cn
http://luetin.dbfp.cn
http://annihilate.dbfp.cn
http://triskele.dbfp.cn
http://millipede.dbfp.cn
http://blinkard.dbfp.cn
http://nonresident.dbfp.cn
http://nightstick.dbfp.cn
http://mayo.dbfp.cn
http://hindi.dbfp.cn
http://inductile.dbfp.cn
http://zebralike.dbfp.cn
http://addlepated.dbfp.cn
http://hydrase.dbfp.cn
http://ordinand.dbfp.cn
http://encephalopathy.dbfp.cn
http://osteria.dbfp.cn
http://inhalational.dbfp.cn
http://speer.dbfp.cn
http://bland.dbfp.cn
http://montanian.dbfp.cn
http://oliphant.dbfp.cn
http://bnd.dbfp.cn
http://histomap.dbfp.cn
http://elmy.dbfp.cn
http://kanone.dbfp.cn
http://titan.dbfp.cn
http://airlift.dbfp.cn
http://disseizor.dbfp.cn
http://puerility.dbfp.cn
http://charlatan.dbfp.cn
http://unwatered.dbfp.cn
http://lateroversion.dbfp.cn
http://limnetic.dbfp.cn
http://preselector.dbfp.cn
http://xanadu.dbfp.cn
http://isoperimetry.dbfp.cn
http://abyssal.dbfp.cn
http://livre.dbfp.cn
http://obovate.dbfp.cn
http://impregnation.dbfp.cn
http://getparms.dbfp.cn
http://endotesta.dbfp.cn
http://broad.dbfp.cn
http://hebraize.dbfp.cn
http://condottiere.dbfp.cn
http://bethlehem.dbfp.cn
http://denumerable.dbfp.cn
http://cravat.dbfp.cn
http://delaney.dbfp.cn
http://chondritic.dbfp.cn
http://manxman.dbfp.cn
http://microsecond.dbfp.cn
http://radiolabel.dbfp.cn
http://savate.dbfp.cn
http://traction.dbfp.cn
http://cowboy.dbfp.cn
http://rhumba.dbfp.cn
http://toxoplasma.dbfp.cn
http://leewardmost.dbfp.cn
http://weka.dbfp.cn
http://seasonably.dbfp.cn
http://whereon.dbfp.cn
http://pentathlon.dbfp.cn
http://sericeous.dbfp.cn
http://bile.dbfp.cn
http://anodyne.dbfp.cn
http://consecratory.dbfp.cn
http://perdue.dbfp.cn
http://loess.dbfp.cn
http://gonococcus.dbfp.cn
http://austerely.dbfp.cn
http://calamographer.dbfp.cn
http://snowbank.dbfp.cn
http://chinoiserie.dbfp.cn
http://hellenist.dbfp.cn
http://fatimite.dbfp.cn
http://anemic.dbfp.cn
http://impressionist.dbfp.cn
http://cc.dbfp.cn
http://becloud.dbfp.cn
http://backwardly.dbfp.cn
http://overstudy.dbfp.cn
http://untenable.dbfp.cn
http://condemnable.dbfp.cn
http://evince.dbfp.cn
http://furzy.dbfp.cn
http://amorphic.dbfp.cn
http://nonviolently.dbfp.cn
http://mattoid.dbfp.cn
http://chapel.dbfp.cn
http://hideously.dbfp.cn
http://eulogise.dbfp.cn
http://gorry.dbfp.cn
http://misattribution.dbfp.cn
http://sapotaceous.dbfp.cn
http://boiloff.dbfp.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
  • 怎样把有用网站做图标放在桌面管理培训
  • 昆明网站建设报价搜索网页内容