数据库各种写法

jdbctemplate

public Map<String,Object> getAndroidVersion(){
        String sql = "select * from zhao_android_version";
        return jdbcTemplate.queryForMap(sql, new Object[]{});
    }

public List<VipPackageEntity> getMessageActivity(){
        String sql = "select * from zhao_vip_package";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(VipPackageEntity.class));
    }

public List<VipPackageEntity> getMessageActivityIOS(){
        String sql = "select id,if(lineation_price = 3,5,lineation_price) as lineation_price,if(activity_price = 1,3,activity_price) as activity_price,vip_day,auto_price,intro_message,type,voucher,last_days from zhao_vip_package";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(VipPackageEntity.class));
    }

public int getNumber(int userId){
        String sql = "select count(*) from tb_vip_user_info where user_id = ?";
        return jdbcTemplate.queryForObject(sql,new Object[]{userId},int.class);
    }

public List<Integer> getUserEndtime(int userId){
        String sql = "select count(*) from tb_vip_user_info where user_id = ?";
        return  jdbcTemplate.queryForList(sql,new Object[]{userId},int.class);
    }

public Date getUserEndtime(int userId){
        String sql = "select createTime from tb_activity_info where userId = ?";
        return jdbcTemplate.queryForObject(sql,new Object[]{userId},Date.class);
    }

public int updateVoucher(Double giftBlance){
        String sql = "insert into tb_user_account(giftBlance) value (?)";
        return jdbcTemplate.update(sql,new Object[]{giftBlance},int.class);
    }

namedjdbctemplate

public Map<String,Object> queryGiveVoucher(Double price){
        String sql = "SELECT IFNULL(SUM(voucher),0) AS voucher,IFNULL(sum(last_days),0) as days FROM zhao_vip_package WHERE activity_price = :price ";
        return dbLinkTemplate.queryForMap(sql, new MapSqlParameterSource().addValue("price",price));
    }

复杂SQL

UPDATE tb_novel_info a,tb_autor_novel b SET a.chapter_num = b.chapterNums,a.total_word = b.totalWords WHERE a.id = b.id

insert into tb_novel_content_sk (NOVEL_ID,CHAPTER_ID,CHAPTER_NAME,content,CREATE_DATE,UPDATE_STATUS,SORT_NO)  select novelId,concat(id,''),REPLACE(REPLACE(capterName,' ',''),' ',''),REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(content,' ',''),'\\t\\t',''),'\\n\\n','<br>  '),'\\r\\n','<br>  '),'\\n','<br>  '),' ',''),createTime,status,sortNum from tb_autor_content where novelId = ?

insert into tb_novel_chapter_sk (novel_id,chapter_id,chapter_name,update_time_str,status,sort_no,ccid,chapterSort,freeStatus,vipflag)  select novelId,concat(id,''),REPLACE(REPLACE(capterName,' ',''),' ',''),DATE_FORMAT(createTime,'%Y-%m-%d %T'),status,sortNum,0,0,0,0 from tb_autor_content where novelId = ?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值