mapperdb Mybatis mapper 单表处理工具开源项目

我要开发同款
匿名用户2015年07月01日
89阅读

技术信息

开源地址
https://github.com/postgres-x2/postgres-x2
授权协议
Apache

作品详情

mapperdb

作用于mybatis的mapper的单表增删改查(mybatisv3.2.4+,无xml配置配置哦)。

1、etity配置

packagecom.demo.domai;importjava.util.Date;importjavax.aotatio.Resource;importorg.apache.ibatis.aotatios.Result;importorg.apache.ibatis.aotatios.SelectKey;importorg.apache.ibatis.type.JdbcType;@ResourcepublicclassBlog{privateItegerid;privateStrigtitle;privateDatepublishtime;privateStrigcotet;publicvoidsetId(Itegerid){this.id=id;}publicvoidsetTitle(Strigtitle){this.title=title;}publicvoidsetPublishtime(Datepublishtime){this.publishtime=publishtime;}publicvoidsetCotet(Strigcotet){this.cotet=cotet;}//callidetity()//SELECTLAST_INSERT_ID()@Result(id=true)@SelectKey(statemet="SELECTLAST_INSERT_ID()",before=false,keyProperty="id",keyColum="id",resultType=Iteger.class)publicItegergetId(){returid;}publicStriggetTitle(){returtitle;}@Result(jdbcType=JdbcType.TIMESTAMP)publicDategetPublishTime(){returpublishtime;}publicStriggetCotet(){returcotet;}}

Result可以配置TypeHadler

2、mybatis配置

publicvoidt(){Objectb=ull;//Mapper添加MapperRegistryProxyproxy=MapperRegistryProxy.use(sqlSessioFactory);proxy.addMapper(BlogMapper.class);SqlSessiosqlSessio=sqlSessioFactory.opeSessio(true);BlogMappermapper=sqlSessio.getMapper(BlogMapper.class);}

MapperRegistryProxy注册mapper模板.

3、sprig整合

<beaclass="com.mapperdb.sprig.MapperScaerCofigurerSupprot"><propertyame="basePackage"value="com.demo.mapper"/><propertyame="sqlSessioFactoryBeaName"value="sqlSessioFactory"/></bea>

其中MapperScaerCofigurerSupprot是mapper模板的扫描器.

4、mapper使用方式

packagecom.demo.mapper;importcom.demo.domai.Blog;importcom.mapperdb.mapper.Mapper;publiciterfaceBlogMapperextedsMapper<Blog>{}

其中BlogMapper继承已经定义好的mapper模板.还可以实现自己的mapper模板.

5、注意事项

text建议和mapper模板和mybatis的mapper不放在同一个包中,方便扫描。

功能介绍

mapperdb 作用于 mybatis 的 mapper 的单表增删改查(mybatis v3.2.4+,无xml配置配置哦)。 1、entity 配置 package com.demo.do...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论