Wapper

一、条件构造器关系介绍(强制)

条件构造器关系介绍 :

上图绿色框为抽象类abstract 蓝色框为正常class类,可new对象 黄色箭头指向为父子类关系,箭头指向为父类

wapper介绍 :

Wrapper : 条件构造抽象类,最顶端父类

AbstractWrapper : 用于查询条件封装,生成 sql 的 where 条件

QueryWrapper : Entity 对象封装操作类,不是用lambda语法

UpdateWrapper : Update 条件封装,用于Entity对象更新操作

AbstractLambdaWrapper : Lambda 语法使用 Wrapper统一处理解析 lambda 获取 column。

LambdaQueryWrapper :看名称也能明白就是用于Lambda语法使用的查询Wrapper

LambdaUpdateWrapper : Lambda 更新封装Wrapper

二、项目实例(操作)

1、根据主键或者简单的查询条件进行查询
    /**
     * 通过单个ID主键进行查询
     */
    @Test
    public void selectById() {
        User user = userMapper.selectById(1094592041087729666L);
        System.out.println(user);
    }
 
    /**
     * 通过多个ID主键查询
     */
    @Test
    public void selectByList() {
        List<Long> longs = Arrays.asList(1094592041087729666L, 1094590409767661570L);
        List<User> users = userMapper.selectBatchIds(longs);
        users.forEach(System.out::println);
    }
 
    /**
     * 通过Map参数进行查询
     */
    @Test
    public void selectByMap() {
        Map<String, Object> params = new HashMap<>();
        params.put("name", "张雨琪");
        List<User> users = userMapper.selectByMap(params);
        users.forEach(System.out::println);
    }
2、MyBatis-Plus还提供了Wrapper条件构造器,具体使用看如下代码:
/**
     * 名字包含雨并且年龄小于40
     * <p>
     * WHERE name LIKE '%雨%' AND age < 40
     */
    @Test
    public void selectByWrapperOne() {
        QueryWrapper<User> wrapper = new QueryWrapper();
        wrapper.like("name", "雨").lt("age", 40);
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 名字包含雨
     * 年龄大于20小于40
     * 邮箱不能为空
     * <p>
     * WHERE name LIKE '%雨%' AND age BETWEEN 20 AND 40 AND email IS NOT NULL
     */
    @Test
    public void selectByWrapperTwo() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.like("name", "雨").between("age", 20, 40).isNotNull("email");
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 名字为王性
     * 或者年龄大于等于25
     * 按照年龄降序排序,年龄相同按照id升序排序
     * <p>
     * WHERE name LIKE '王%' OR age >= 25 ORDER BY age DESC , id ASC
     */
    @Test
    public void selectByWrapperThree() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.likeRight("name", "王").or()
                .ge("age", 25).orderByDesc("age").orderByAsc("id");
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 查询创建时间为2019年2月14
     * 并且上级领导姓王
     * <p>
     * WHERE date_format(create_time,'%Y-%m-%d') = '2019-02-14' AND manager_id IN (select id from user where name like '王%')
     */
    @Test
    public void selectByWrapperFour() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.apply("date_format(create_time,'%Y-%m-%d') = {0}", "2019-02-14")
                .inSql("manager_id", "select id from user where name like '王%'");
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 查询王姓
     * 并且年龄小于40或者邮箱不为空
     * <p>
     * WHERE name LIKE '王%' AND ( age < 40 OR email IS NOT NULL )
     */
    @Test
    public void selectByWrapperFive() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.likeRight("name", "王").and(qw -> qw.lt("age", 40).or().isNotNull("email"));
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 查询王姓
     * 并且年龄大于20 、年龄小于40、邮箱不能为空
     * <p>
     * WHERE name LIKE ? OR ( age BETWEEN ? AND ? AND email IS NOT NULL )
     */
    @Test
    public void selectByWrapperSix() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.likeRight("name", "王").or(
                qw -> qw.between("age", 20, 40).isNotNull("email")
        );
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * (年龄小于40或者邮箱不为空) 并且名字姓王
     * WHERE ( age < 40 OR email IS NOT NULL ) AND name LIKE '王%'
     */
    @Test
    public void selectByWrapperSeven() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.nested(qw -> qw.lt("age", 40).or().isNotNull("email"))
                .likeRight("name", "王");
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 查询年龄为30、31、32
     * WHERE age IN (?,?,?)
     */
    @Test
    public void selectByWrapperEight() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.in("age", Arrays.asList(30, 31, 32));
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }
 
    /**
     * 查询一条数据
     * limit 1
     */
    @Test
    public void selectByWrapperNine() {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.in("age", Arrays.asList(30, 31, 32)).last("limit 1");
        List<User> users = userMapper.selectList(wrapper);
        users.forEach(System.out::println);
    }

三、条件构造器方法的使用(操作)

注意:以下条件构造器的方法入参中的 column均表示数据库字段

1、ge、gt、le、lt、isNull、isNotNull
 
@Test
public void testDelete() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper
        .isNull("name")
        .ge("age", 12)
        .isNotNull("email");
    int result = userMapper.delete(queryWrapper);
    System.out.println("delete return count = " + result);
}

SQL:UPDATE user SET deleted=1 WHERE deleted=0 AND name IS NULL AND age >= ? AND email IS NOT NULL

2、eq、ne

注意:seletOne返回的是一条实体记录,当出现多条时会报错

@Test
public void testSelectOne() {
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("name", "Tom");
 
    User user = userMapper.selectOne(queryWrapper);
    System.out.println(user);
}
3、between、notBetween

包含大小边界

@Test
public void testSelectCount() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.between("age", 20, 30);
 
    Integer count = userMapper.selectCount(queryWrapper);
    System.out.println(count);
}

SELECT COUNT(1) FROM user WHERE deleted=0 AND age BETWEEN ? AND ?

4、allEq
@Test
public void testSelectList() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    Map<String, Object> map = new HashMap<>();
    map.put("id", 2);
    map.put("name", "Jack");
    map.put("age", 20);9
 
    queryWrapper.allEq(map);
    List<User> users = userMapper.selectList(queryWrapper);
 
    users.forEach(System.out::println);
}

SELECT id,name,age,email,create_time,update_time,deleted,version FROM user WHERE deleted=0 AND name = ? AND id = ? AND age = ?

5、like、notLike、likeLeft、likeRight

selectMaps返回Map集合列表

@Test
public void testSelectMaps() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper
        .notLike("name", "e")
        .likeRight("email", "t");
 
    List<Map<String, Object>> maps = userMapper.selectMaps(queryWrapper);//返回值是Map列表
    maps.forEach(System.out::println);
}

SELECT id,name,age,email,create_time,update_time,deleted,version FROM user WHERE deleted=0 AND name NOT LIKE ? AND email LIKE ?

6、in、notIn、inSql、notinSql、exists、notExists

in、notIn:

notIn("age",{1,2,3})--->age not in (1,2,3)
notIn("age", 1, 2, 3)--->age not in (1,2,3)

inSql、notinSql:可以实现子查询

例: inSql("age", "1,2,3,4,5,6")--->age in (1,2,3,4,5,6)
例: inSql("id", "select id from table where id < 3")--->id in (select id from table where id < 3)
@Test
public void testSelectObjs() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    //queryWrapper.in("id", 1, 2, 3);
    queryWrapper.inSql("id", "select id from user where id < 3");
 
    List<Object> objects = userMapper.selectObjs(queryWrapper);//返回值是Object列表
    objects.forEach(System.out::println);
}

SELECT id,name,age,email,create_time,update_time,deleted,version FROM user WHERE deleted=0 AND id IN (select id from user where id < 3)

7、or、and

注意:这里使用的是 UpdateWrapper 不调用or则默认为使用 and 连

@Test
public void testUpdate1() {
 
    //修改值
    User user = new User();
    user.setAge(99);
    user.setName("Andy");
 
    //修改条件
    UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
    userUpdateWrapper
        .like("name", "h")
        .or()
        .between("age", 20, 30);
 
    int result = userMapper.update(user, userUpdateWrapper);
    System.out.println(result);
}

UPDATE user SET name=?, age=?, update_time=? WHERE deleted=0 AND name LIKE ? OR age BETWEEN ? AND ?

8、嵌套or、嵌套and

这里使用了lambda表达式,or中的表达式最后翻译成sql时会被加上圆括号

@Test
public void testUpdate2() {
 
    //修改值
    User user = new User();
    user.setAge(99);
    user.setName("Andy");
 
    //修改条件
    UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
    userUpdateWrapper
        .like("name", "h")
        .or(i -> i.eq("name", "李白").ne("age", 20));
 
    int result = userMapper.update(user, userUpdateWrapper);
    System.out.println(result);
}

UPDATE user SET name=?, age=?, update_time=?

WHERE deleted=0 AND name LIKE ?

OR ( name = ? AND age <> ? )

9、orderBy、orderByDesc、orderByAsc
@Test
public void testSelectListOrderBy() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.orderByDesc("id");
 
    List<User> users = userMapper.selectList(queryWrapper);
    users.forEach(System.out::println);
}

SELECT id,name,age,email,create_time,update_time,deleted,version

FROM user WHERE deleted=0 ORDER BY id DESC

10、last

直接拼接到 sql 的最后

注意:只能调用一次,多次调用以最后一次为准 有sql注入的风险,请谨慎使用

@Test
public void testSelectListLast() {
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.last("limit 1");
 
    List<User> users = userMapper.selectList(queryWrapper);
    users.forEach(System.out::println);
}

SELECT id,name,age,email,create_time,update_time,deleted,version

FROM user WHERE deleted=0 limit 1

11、指定要查询的列
@Test
public void testSelectListColumn() {
 
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.select("id", "name", "age");
 
    List<User> users = userMapper.selectList(queryWrapper);
    users.forEach(System.out::println);
}

SELECT id,name,age FROM user WHERE deleted=0

12、set、setSql

最终的sql会合并 user.setAge(),以及 userUpdateWrapper.set() 和 setSql() 中 的字段

@Test
public void testUpdateSet() {
    //修改值
    User user = new User();
    user.setAge(99);
 
    //修改条件
    UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
    userUpdateWrapper
        .like("name", "h")
        .set("name", "老李头")//除了可以查询还可以使用set设置修改的字段
        .setSql(" email = '123@qq.com'");//可以有子查询
    int result = userMapper.update(user, userUpdateWrapper);
}

UPDATE user SET age=?, update_time=?, name=?, email = '123@qq.com' WHERE deleted=0 AND name LIKE ?

<template> <view class="wapper"> <!-- <view class="bg-image"></view> --> <image class="bg-image" src="/static/home/bus/bg-image.png" mode="widthFix" style="width: 100%;" /> <!-- 自定义导航栏 --> <view class="custom-navbar" :style="{ paddingTop: statusBarHeight + 'px' }"> <view class="navbar-content"> <!-- 左侧返回按钮 --> <view class="back-btn" @click="handleBack"> <image src="/static/home/bus/back-icon.png" mode="aspectFit" style="width: 48rpx;height: 48rpx;" /> </view> <!-- 中间标题 --> <text class="title">{{busLineBase.name}}</text> </view> </view> <view class="wapper-content" :style="{ paddingTop: statusBarHeight +50 + 'px' }"> <view class="line_info"> <view class="site"> <text class="from">{{busLineBase.startSn}}</text> <view class="arrow"> <text class="to">{{busLineBase.endSn}}</text> </view> </view> <view class="tit"> <view class="time_s"> <text class="time-text">{{busLineBase.firstTime}}</text> </view> <view class="time_e"> <text class="time-text">{{busLineBase.lastTime}}</text> </view> <text class="price">票价: {{busLineBase.price}}</text> </view> </view> <view class="distance-class"> <view class="station"> <view class="station-title"> <view class="station-name">候车站</view> <view class="station-content"> <view class="active">{{stationName}}</view> <view class="underline"></view> </view> </view> </view> <view class="distance" v-if="state==0 && travelOrder!=0"> <view class="time"> <text class="time_title">{{Math.ceil(travelTime/60)}}分钟</text> </view> <text class="arr">{{travelOrder}}站/ <text v-if="travelDistance<1000">{{numFilter(travelDistance)}}m</text> <text v-else>{{numFilter(travelDistance/1000)}}km</text> </text> </view> <view class="distance" v-else-if="state==0 && travelOrder==0 && isArrive==1"> <view class="time"> <view class="bus-arr">已到站</view> </view> </view> <view class="distance" v-else-if="state==0 &&isArrive==0"> <view class="time"> <view class="bus-coming">即将到站 {{travelDistance}}m</view> </view> </view> <view class="distance" v-else-if="state==-1"> <view class="time"> <view class="none">等待发车</view> </view> </view> <view class="distance" v-else> <view class="time"> <view class="none">暂无车辆信息</view> </view> </view> <!-- <view>已到站</view> --> </view> </view> <view class="site_list"> <scroll-view class="wapper_sitelist" scroll-x="true" scroll-with-animation :scroll-into-view="targetId"> <view class="road"> <view class='part' v-for="(item, index) in siteList" @click="showActive(index, item.sn)"> <view :id="'id'+item.sid" class='name'> <view> <view class="dot_p" :class="{'dot_p_show': ind === index}"></view> <view class='dot_r' v-if="index!=siteList.length-1"></view> </view> <div :class="item.state==1?'road-bus':'road-bus-coming'" v-if="item.isHaveBus==0"></div> <view class='dot_d' :class="{'dot_d_show': ind === index}"></view> <view class='text' :class="{'text_show': ind === index}"> <view>{{index +1}}</view> <view class="text-dir"> {{item.sn}} </view> </view> </view> </view> </view> </scroll-view> <!-- <view class="my-map"></view> --> </view> <view class="my-map"> 223123 <web-view ref="webview" :webview-styles="webviewStyles" :src="src" @onPostMessage="getMessage"></web-view> </view> </view> </template> <script> import { getRealTimeBusLine, getRealTimeBusLineStation } from '@/request/bus.js' export default { data() { return { src: '', timer: null, isArrive: 0, targetId: '', state: 0, stationName: '', travelDistance: 0, travelTime: 0, travelOrder: 0, ratio: '', ind: '', siteId: "", lineName: "二号线", siteName: "动漫园站", siteList: [], busLineBase: [], stateBus: [], time_s: '', time_e: '', from: '', busPosition: [0, 5, 11], to: '', isActive: false, lineId: '', siteNum: '0', haveBus: true, webviewStyles: { position: 'absolute', top: '850px', bottom: '30px', // zIndex: '999', marginTop: '850px', marginLeft: '20px', marginRight: '20px', marginBottom: '10px', height: '500px' } // 保留原有数据项... } }, onLoad(options) { // 获取路由参数 const { statusBarHeight } = uni.getSystemInfoSync() // const systemInfo = uni.getSystemInfoSync(); // this.ratio = (systemInfo.windowWidth / 750) / 0.5 console.log("options", options) this.statusBarHeight = statusBarHeight this.lineId = options.lineId this.lat = options.lat this.lng = options.lng this.lineName = options.lineName this.getLineDetail() if (this.timer) { clearInterval(this.timer); this.timer = null; } // this.timer = setInterval(() => { // console.log("30") // this.refresh() // }, 1000 * 30); this.init() }, methods: { init() { setTimeout(() => { this.src = '../../../../hybrid/html/map.html' }, 1000); }, handlePostMessage(res) { this.$refs.webview.evalJs(`handleMessage()`); }, getMessage(e) { uni.showModal({ content: "111", showCancel: false }) }, numFilter(value) { if (value != 0) { // 将数值转换为浮点数,并保留两位小数 let realVal = parseFloat(value).toFixed(2); return realVal; } }, async getLineDetail() { var res = await getRealTimeBusLine({ lineId: this.lineId, lat: this.lat, lng: this.lng }) if (res.code == 0) { console.log("1", res) this.siteList = res.data.busInfStop var ind = res.data.targetOrder this.ind = res.data.targetOrder - 1 this.stationName = this.siteList[ind - 1].sn this.state = res.data.state this.busLineBase = res.data.busLineBase this.targetOrder = res.data.targetOrder this.$nextTick(function() { this.targetId = 'id' + this.siteList[ind - 4].sid }); if (this.state == 0) { this.stateBus = res.data.stateBus var travelsList = this.stateBus.travels this.distance = this.findAllClosest(this.stateBus, this.targetOrder) if (this.distance.length != 0) { var travels = this.distance[0].travels this.travelDistance = travels[0].travelDistance this.travelOrder = travels[0].travelOrder this.travelTime = travels[0].travelTime this.siteList = this.processArrays(this.siteList, this.stateBus, 'order', 'state'); } } } }, async showActive(index, siteName) { this.ind = index this.stationName = siteName var res = await getRealTimeBusLineStation({ lineId: this.lineId, stationName: this.stationName }) if (res.code == 0) { this.siteList = res.data.busInfStop var ind = res.data.targetOrder this.stationName = this.siteList[ind - 1].sn this.state = res.data.state this.busLineBase = res.data.busLineBase this.ind = res.data.targetOrder - 1 this.targetOrder = res.data.targetOrder this.$nextTick(function() { this.targetId = 'id' + this.siteList[ind - 4].sid }); if (this.state == 0) { this.stateBus = res.data.stateBus var travelsList = this.stateBus.travels this.distance = this.findAllClosest(this.stateBus, this.targetOrder) if (this.distance.length != 0) { var travels = this.distance[0].travels this.travelDistance = travels[0].travelDistance this.travelOrder = travels[0].travelOrder this.travelTime = travels[0].travelTime this.isArrive = this.distance[0].state this.siteList = this.processArrays(this.siteList, this.stateBus, 'order', 'state'); } } } }, handleBack() { uni.navigateBack() }, async refresh() { console.log("刷新") var res = await getRealTimeBusLineStation({ lineId: this.lineId, stationName: this.stationName }) if (res.code == 0) { this.siteList = res.data.busInfStop var ind = res.data.targetOrder this.stationName = this.siteList[ind - 1].sn this.state = res.data.state this.busLineBase = res.data.busLineBase this.ind = res.data.targetOrder - 1 this.targetOrder = res.data.targetOrder this.$nextTick(function() { this.targetId = 'id' + this.siteList[ind - 4].sid }); if (this.state == 0) { this.stateBus = res.data.stateBus var travelsList = this.stateBus.travels this.distance = this.findAllClosest(this.stateBus, this .targetOrder) if (this.distance.length != 0) { var travels = this.distance[0].travels this.travelDistance = travels[0].travelDistance this.travelOrder = travels[0].travelOrder this.travelTime = travels[0].travelTime this.isArrive = this.distance[0].state this.siteList = this.processArrays(this.siteList, this .stateBus, 'order', 'state'); } } } }, // 找到距离最近车站的小车 findAllClosest(arr, target) { const validItems = arr.filter(item => item.order < target + 1); if (validItems.length === 0) return []; const distances = validItems.map(item => ({ item, distance: Math.abs(item.order - target) })); if (distances.length != 0) { const minDist = Math.min(...distances.map(d => d.distance)); return distances.filter(d => d.distance === minDist).map(d => d.item); } }, processArrays(arrayA, arrayB, key, valueKey) { // 创建arrayB的快速查找映射(基于指定键) const bMap = new Map(); arrayB.forEach(item => { if (item[key] !== undefined) { bMap.set(item[key], item); } }); // 遍历arrayA并添加属性 return arrayA.map(itemA => { // 浅拷贝避免修改原对象 const newItem = { ...itemA }; // 检查是否存在匹配元素 if (bMap.has(newItem[key])) { const matchedB = bMap.get(newItem[key]); // newItem.state = 0; newItem.isHaveBus = 0; // 添加arrayB中的属性值(如果存在) if (matchedB[valueKey] !== undefined) { newItem[valueKey] = matchedB[valueKey]; } } return newItem; }); } }, onPullDownRefresh() { console.log("下拉") this.refresh() setTimeout(() => { //结束下拉刷新 uni.stopPullDownRefresh(); }, 1000); }, onUnload() { console.log('页面即将卸载'); if (this.timer) { clearInterval(this.timer); this.timer = null; } } } </script> <style> page { background-color: #f5f5f5; } </style> <style scoped> .bg-image { position: absolute; } .custom-navbar { position: absolute; top: 0; left: 0; width: 100%; z-index: 1000; /* 自定义背景色 */ /* 自定义阴影 */ } .navbar-content { height: 44px; /* 标准导航栏高度 */ display: flex; align-items: center; padding: 0 15px; } .title { flex: 1; text-align: center; font-size: 17px; font-weight: bold; color: #333; /* 标题颜色 */ } .back-btn { width: 48rpx; height: 48rpx; } .right-area { width: 40px; text-align: right; } .info_wapper { height: 156px; /* background: #36A3F9; */ /* background: url(@/static/home/bus/detail-bg.png) left no-repeat; */ padding: 15px; color: black; position: absolute; z-index: 9; width: 100%; } .line_info { position: relative; /* display: flex; */ } .site { font-size: 32rpx; color: black; margin-bottom: 10px; text-align: left; display: flex; margin-left: 30px; } .from { /* padding-left: 52rpx; */ color: black; } .arrow { background: url(@/static/home/bus/single.png) left no-repeat; background-size: 14px 5px; margin-left: 10px; color: black; } .to { padding-left: 26px; color: black; } .time_s { background: url(@/static/home/bus/start.png) left no-repeat; background-size: 18px 18px; justify-self: baseline; } .time_e { background: url(@/static/home/bus/end.png) left no-repeat; background-size: 18px 18px; margin-left: 15px; } .price { margin-left: 15px; } .tit { color: #fff; font-size: 26rpx; /* padding-left: 52rpx; */ margin-bottom: 10px; height: 21px; color: #333; display: flex; align-items: baseline; margin-left: 30px; } .distance-class { border-radius: 15px; /* box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1); */ background: url(@/static/home/bus/distance-bg.png) center no-repeat; background-size: cover; height: 160px; position: absolute; z-index: 99; left: 20px; right: 20px; } .distance { color: #B7BABB; line-height: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; position: relative; z-index: 99; /* align-items: baseline; */ } .time { color: aquamarine; } .bus-arr { color: rgb(255, 164, 17); font-weight: bold; margin-top: 10px; } .bus-coming { color: rgb(55, 170, 126); font-weight: bold; margin-top: 10px; } .station { margin-left: 20px; color: #353738; padding: 10px; } .station-title { display: flex; align-items: baseline; } .station-name { margin-right: 15px; } .station-content { padding-top: 10px; /* padding-left: 20rpx; */ position: relative; /* padding-right: 50rpx; */ /* 确保文字在下划线上方 */ z-index: 2; justify-content: center; display: flex; align-items: center; /* 文字在上层 */ } .underline { position: absolute; bottom: 2px; height: 3px; background: linear-gradient(to right, rgb(110, 207, 169), rgb(110, 224, 176)); /* 下划线颜色 */ border-radius: 3px; z-index: -1; width: 80%; align-items: center; justify-content: center; display: flex; /* margin-left: 30rpx; */ /* width: 60rpx; */ /* 下划线在文字下方 */ } .active { color: black; /* 激活状态文字颜色 */ font-weight: bold; /* font-size: 36rpx; */ } .time { float: left; width: 40%; font-size: 26rpx; /* height: 130rpx; */ line-height: 40px; } .time { font-size: 36rpx; color: #353738; } .time-text { margin-left: 25px; } .time_title { color: rgb(14, 170, 112); font-weight: bold; } .arr { float: left; /* width: 20%; */ font-size: 30rpx; color: rgb(14, 170, 112); } .site_list { /* margin: 15px; */ /* box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1); */ background-color: white; border-radius: 15px; margin-top: 150px; padding-left: 15px; padding-right: 15px; padding-top: 15px; padding-bottom: 10px; background: url(@/static/home/bus/site-bg.png) center no-repeat; position: absolute; z-index: 99; left: 20px; right: 20px; background-size: cover; /* 让背景图片覆盖整个视口 */ } .site_list .wapper_sitelist { width: 100%; overflow-x: scroll; position: relative; -webkit-overflow-scrolling: touch; display: flex; } .bus_road { background: url(@/static/home/bus/bus.png) no-repeat center; background-size: cover; width: 28px; height: 14px; position: absolute; z-index: 1; margin-top: 4px; left: 14px; /* margin-top: -40px; */ } .road-bus { background: url(@/static/home/bus/bus.png) no-repeat center; background-size: cover; width: 28px; height: 14px; position: absolute; z-index: 1; margin-top: -35px; margin-left: 10px; /* left: 14px; */ /* margin-top: -40px; */ } .road-bus-coming { background: url(@/static/home/bus/bus.png) no-repeat center; background-size: cover; width: 28px; height: 14px; position: absolute; z-index: 1; margin-top: -35px; margin-left: -40px; } .road { display: flex; } .wapper_sitelist::-webkit-scrollbar { display: none; } /deep/::-webkit-scrollbar { display: none; width: 0; height: 0; } .part { padding: 10px; display: flex; flex-direction: row; text-align: center; justify-content: center; padding-top: 30px; } .site_list .dot_r { margin-top: 25px; position: absolute; top: 23px; height: 3px; background: linear-gradient(to right, rgb(110, 207, 169), rgb(110, 224, 176)); /* 下划线颜色 */ width: 46px; border-radius: 3rpx; z-index: 1; margin-left: 4px; align-items: center; justify-content: center; display: flex; } .site_list .name { margin-top: 28px; display: flex; flex-direction: column; align-items: center; } .site_list .text { display: flex; text-align: center; margin-left: 5px; flex-direction: column; } .site_list .text_show { display: flex; text-align: center; margin-left: 5px; color: rgb(14, 170, 112); font-weight: bold; } .site_list .dot_show { background: url(@/static/home/bus/position_red.png) no-repeat center; background-size: 14px 18px; } .site_list .dot_d_show { border-radius: 50%; width: 16px; height: 16px; background-color: rgba(110, 207, 169, 0.5); position: absolute; z-index: 999; top: 41px; margin-left: 8px; display: flex; align-items: center; justify-content: center; } .road-class { display: flex; } .dot_p { border-radius: 50%; width: 8px; height: 8px; background-color: rgb(110, 207, 169); position: absolute; z-index: 999; top: 45px; display: flex; align-items: center; justify-content: center; /* margin-right: 2px; */ /* margin-left: 10rpx; */ } .dot_p_show { border-radius: 50%; width: 8px; height: 8px; background-color: rgb(14, 170, 112); position: absolute; z-index: 999; top: 45px; display: flex; align-items: center; justify-content: center; } .text-dir { margin-top: 5px; writing-mode: vertical-rl; letter-spacing: 3px; } .none { color: #848484; font-size: 16px; margin-top: 15px; } .my-map { /* width: 100%; */ position: absolute; z-index: 999; /* bottom: 20px; */ /* background-color: white; */ /* margin-bottom: 50px; */ left: 0; right: 0; top: 650px; margin: 20px; height: 370px; } .map { margin-top: 500px; margin-left: 20px; margin-right: 20px; margin-bottom: 10px; /* z-index: 9999; */ } </style> 将uniapp写法转化为h5
07-04
<think>我们正在讨论MyBatis-Plus中的Wrapper类,特别是EntityWrapper在3.x版本中被弃用后的替代品。根据之前的对话,用户已经了解了QueryWrapper和LambdaQueryWrapper的使用方法。现在用户的问题是:“我想查找Wrapper所在的包 请问Wrapper所在的包”。 根据之前的回答,我们知道: - QueryWrapper 和 UpdateWrapper 在 MyBatis-Plus 3.x 中位于包 `com.baomidou.mybatisplus.core.conditions.query.QueryWrapper` 和 `com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper` - 而LambdaQueryWrapper和LambdaUpdateWrapper也在同一个包下(conditions包下) 另外,用户提供的引用[4]中出现了EntityWrapper,但这是旧版的,位于`com.baomidou.mybatisplus.mapper.EntityWrapper`(在3.x中已弃用)。 因此,对于当前3.x版本,我们应推荐新的包路径。 但是,用户现在明确问的是“Wrapper所在的包”,这里需要区分不同类型的Wrapper。 我们可以这样回答: 1. 对于查询条件构造器,使用`QueryWrapper`,其包名为:`com.baomidou.mybatisplus.core.conditions.query.QueryWrapper` 2. 对于更新条件构造器,使用`UpdateWrapper`,其包名为:`com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper` 3. 对于Lambda表达式写法,`LambdaQueryWrapper`和`LambdaUpdateWrapper`也在上述对应包内(因为LambdaQueryWrapper是QueryWrapper的子类,在同一包下) 注意:用户可能只是想知道如何导入这些类,所以给出具体的包路径即可。 同时,根据用户引用的内容,引用[4]中使用了EntityWrapper,但我们不建议使用,所以应该强调新的包路径。 另外,用户提供的引用[1]和[2]是关于C++和Java Service Wrapper的,与MyBatis-Plus无关,可以忽略;引用[3]和[5]也不相关。 因此,回答重点:明确指出新版本中各种Wrapper的包路径。 同时,按照要求生成相关问题。 </think>关于 MyBatis-Plus 中 Wrapper 类的包路径,根据版本和使用场景不同有以下分类: ### 📦 Wrapper 类所在包路径 1. **查询构造器** - **`QueryWrapper`** `com.baomidou.mybatisplus.core.conditions.query.QueryWrapper` ```java // 使用示例 QueryWrapper<User> qw = new QueryWrapper<>(); qw.eq("status", 1).orderByDesc("create_time"); ``` - **`LambdaQueryWrapper`** `com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper` ```java // 使用示例(类型安全) LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>(); lqw.eq(User::getStatus, 1).orderByDesc(User::getCreateTime); ``` 2. **更新构造器** - **`UpdateWrapper`** `com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper` ```java // 使用示例 UpdateWrapper<User> uw = new UpdateWrapper<>(); uw.set("name", "Alice").eq("id", 1001); ``` - **`LambdaUpdateWrapper`** `com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper` ```java // 使用示例(类型安全) LambdaUpdateWrapper<User> luw = new LambdaUpdateWrapper<>(); luw.set(User::getName, "Alice").eq(User::getId, 1001); ``` 3. **历史版本弃用类(3.x 不推荐)** - **`EntityWrapper`** `com.baomidou.mybatisplus.mapper.EntityWrapper`(已弃用)[^4] --- ### 🔍 验证方法 在 IDE 中通过以下方式确认: 1. 按住 `Ctrl` 点击 Wrapper 类名 2. 查看导入语句: ```java import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; ``` > ️ **注意**:MyBatis-Plus ≥ 3.x 版本中,所有核心 Wrapper 类均迁移至 **`com.baomidou.mybatisplus.core.conditions`** 包下[^1][^4]。 --- ### 📚 相关参考 | 引用内容 | 来源说明 | |----------|----------| | [^1] | C++的`std::reference_wrapper`(不相关) | | [^2][^3] | Java Service Wrapper部署配置(不相关) | | [^4] | MyBatis-Plus旧版`EntityWrapper`示例(已弃用) | | [^5] | 第三方技术博客(可参考迁移方案) |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值