mybatis中不用mapper.xml方式使用动态sql

Mapper接口中代码(com.dao.ActivityMapper)

@SelectProvider(type=ActivityMapperProvider.class,method="select")
public List<Activity> getActivityAll(Map<String,Object> map);

Provider接口中代码(com.dao.provider.ActivityMapperProvider)

public String select(final Map<String,Object> map){
        return new SQL(){
            {
                SELECT("*");
                FROM("t_activity");
                StringBuffer sb = new StringBuffer();
                if(map.get("ac_type") != null){
                    sb.append(" and ac_type= '"+map.get("ac_type")+"'");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString().replace("and", ""));
                }
            }
        }.toString();
    }

数据库ddl

drop table if exists t_activity;
create table if not exists t_activity(
    ac_id int(11) not null primary key auto_increment comment '自增id主键',
    ac_title varchar(20) comment '活动标题',
    ac_content varchar(225) comment '活动内容',
    ac_place varchar(40) comment '活动地点',
    ac_starttime timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '开始时间',
    ac_endtime timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '结束时间',
    ac_host varchar(20) comment '主持人',
    ac_guest varchar(20) comment '特邀嘉宾',
    ac_money decimal(7,2) default 0 comment '活动报名费,0表示免费,活动可以免费也可以付费',
    ac_limitnum int(10) comment '人数限制',
    ac_fixperson varchar(20) comment '针对人群',
    ac_type tinyint(1) default 0 comment '活动类型,0表示读书会活动,1表示讲座活动',
    ac_status tinyint(1) default 0 comment '活动状态,0表示未开始,1表示正在进行,2表示已经结束',
    ac_applystart timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '报名开始时间',
    ac_applyend timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '报名结束时间',
    ac_createtime timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '创建时间',
    ac_modifytime timestamp default '2017-01-01 00:00:00' on update current_timestamp comment '修改时间'
);
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Geek_U

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值