mybatis多条件语句查询

110 篇文章 0 订阅
8 篇文章 0 订阅

mybatis多条件语句查询

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!-- namespace命名空间,作用就是对sql进行分类化的管理,理解为sql隔离
    注意:使用mapper代理开发时,namespace有特殊作用,namespace等于mapper接口地址
 -->
 <mapper namespace="com.yanshu.service.SpTopKeywordService" >
<!--只能针对一个表进行操作  一对一查询 -->
<select id="sptopshowID"  parameterType="Map" resultType="com.yanshu.pojo.SpTopKeyword">
select * from Spider_Top_Keyword 
</select>
<select id="sptopshow"  parameterType="Map" resultType="com.yanshu.pojo.SpTopKeyword">
select * from Spider_Top_Keyword 
 
<where>
<if test="status!=null and status!='' ">
  status=#{status}
 </if>
 <if test="leveA!=null and leveA!='' ">
 and leveA=#{leveA}
 </if>
 <if test="leveB!=null and leveB!='' ">
 and leveB=#{leveB}
 </if>
 <if test="leveC!=null and leveC!='' ">
 and leveC=#{leveC}
 </if>
</where>
limit  0,  200 
</select>


</mapper>

service和dao层省略....

controller层

package com.yanshu.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.alibaba.fastjson.JSON;
import com.yanshu.dao.SpTopKeywordDao;
import com.yanshu.dao.SpTopKeywordDaoJpa;
import com.yanshu.pojo.Business;
import com.yanshu.pojo.SpTopKeyword;
import com.yanshu.pojo.SpTopKeywordJpa;
import com.yanshu.service.SpTopKeywordService;
import com.yanshu.utils.JsonUtil;


@RestController
@CrossOrigin
public class SpTopKeywordController {
Queue<SpTopKeyword> queue = new LinkedList<>();
Queue<SpTopKeyword> queue1 = new LinkedList<>();
//任务:queue 0 和1
//查询:关键词
//update 
@Autowired
private SpTopKeywordDao sptopdao;
@Autowired
private SpTopKeywordDaoJpa sptopjpa;
@Autowired
private SpTopKeywordService sptopservice;
@RequestMapping("/sptopkey")
public String getSpTopKeyword(String status,String leveC,String leveA,String leveB)
{
Map map=new HashMap();
map.put("leveA", leveA);
map.put("leveB", leveB);
map.put("leveC", leveC);
map.put("status", status);
if(status.equals("1"))
{
//得到的数据
//List<SpTopKeyword> listuser=sptopdao.getSpTopKeyword(status);
List<SpTopKeyword> listuser=sptopservice.sptopshow(map);
//把所有的数据放到Queue中
for (SpTopKeyword object : listuser) {
queue.offer(object);
}
//每次请求获取10个状态为0 的关键词。队列中保存200关键词。
List<SpTopKeyword> returnUsers=new ArrayList<>();
for(int i=1;i<=10;i++)
{
returnUsers.add(queue.poll());

}
return returnUsers!=null?JSON.toJSONString(returnUsers):JsonUtil.objectStatus(4);
}
else
{
//得到的数据
//List<SpTopKeyword> listuser=sptopdao.getSpTopKeyword(status);
List<SpTopKeyword> listuser=sptopservice.sptopshow(map);
//把所有的数据放到Queue中
for (SpTopKeyword object : listuser) {
queue1.offer(object);
}
//每次请求获取10个状态为0 的关键词。队列中保存200关键词。
List<SpTopKeyword> returnUsers=new ArrayList<>();
for(int i=1;i<=10;i++)
{
returnUsers.add(queue1.poll());

}
return returnUsers!=null?JSON.toJSONString(returnUsers):JsonUtil.objectStatus(4);
}


}



@RequestMapping("/upsptopkey")
public String updateSpTopKeyword(String status,String leveA,String leveB,String leveC)
{

Map map=new HashMap();
map.put("leveA", leveA);
map.put("leveB", leveB);
map.put("leveC", leveC);
map.put("status", status);
List<SpTopKeyword> listuser=sptopservice.sptopshow(map);
System.out.println(listuser);
return listuser!=null?JSON.toJSONString(listuser):JsonUtil.objectStatus(4);

}







}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值