当前位置: 首页 > news >正文

深圳网站建设民治大道网站建设优化收费

深圳网站建设民治大道,网站建设优化收费,做个网站好还是做淘宝好,广告创意设计总结在MyBatisPlus中实现多表查询,主要有以下几种方法: 使用注解进行多表查询: 你可以在Mapper接口中使用Select注解来编写SQL查询语句,实现多表查询。例如,如果你想根据用户ID查询用户信息和对应的区域名称,可…

在MyBatisPlus中实现多表查询,主要有以下几种方法:

  1. 使用注解进行多表查询: 你可以在Mapper接口中使用@Select注解来编写SQL查询语句,实现多表查询。例如,如果你想根据用户ID查询用户信息和对应的区域名称,可以这样写:

    @Select("SELECT user.*, area.area_name FROM user, area WHERE user.area_id = area.id AND user.id = #{id}")
    User getUserById(int id);

    这种方法适用于简单的多表查询场景。

  2. 使用MyBatis-Plus Join扩展: MyBatis-Plus Join是一个扩展库,它提供了多表联查的能力。你可以通过配置Join条件来实现多表查询,这种方式更加灵活,适用于复杂的多表查询场景。

  3. 使用XML配置文件进行多表查询: 另一种方法是在Mapper的XML配置文件中定义多表查询的SQL语句。例如:

    <mapper namespace="com.yourpackage.mapper.UserMapper"><resultMap id="userMap" type="com.yourpackage.model.UserVO"><result property="userName" column="name"/><result property="userAge" column="age"/><!-- 其他字段映射 --></resultMap><select id="selectUsers" resultMap="userMap">SELECT u.name, u.age, a.area_nameFROM t_user as uLEFT JOIN t_area as a ON u.area_id = a.id</select>
    </mapper>

    这种方式适用于需要复杂SQL逻辑和字段映射的场景。

  4. 动态查询(通过join): 使用MyBatis-Plus的动态SQL功能,可以在运行时构建多表查询。例如:

    @Select("SELECT t_blog.*, t_user.* " +" FROM t_blog " +"   LEFT JOIN t_user " +"     ON t_blog.user_id = t_user.id " +" ${ew.customSqlSegment} ")
    IPage<BlogVO> findBlogByJoin(IPage<BlogVO> page, @Param("ew") Wrapper wrapper);

    这种方式适用于需要动态构建查询条件的场景。

以上方法可以根据你的具体需求和项目情况选择使用,每种方法都有其适用的场景和优势。

要使用MyBatis-Plus Join扩展(简称MPJ),你可以按照以下步骤进行操作:

  1. 引入依赖: 首先,你需要在你的项目中引入MyBatis-Plus-Join的依赖。如果你使用Maven,可以在pom.xml文件中添加如下依赖:

    <!-- mybatis-plus-join -->
    <dependency><groupId>com.github.yulichang</groupId><artifactId>mybatis-plus-join</artifactId><version>1.1.6</version>
    </dependency>

    确保你的MyBatis-Plus版本大于等于3.4.0。

  2. 配置Mapper扫描: 在你的Spring Boot应用中,确保配置了Mapper接口的扫描路径:

    @MapperScan("com.yourpackage.mapper")
    @SpringBootApplication
    public class YourApplication {public static void main(String[] args) {SpringApplication.run(YourApplication.class, args);}
    }
  3. 使用MPJ进行多表查询: 在你的Mapper接口中,你可以使用MPJ提供的API来构建多表查询。以下是一个简单的例子,展示了如何使用MPJ进行多表联合查询:

    @Override
    public List<ObOutPoolDto> queryByOrderNumber(String orderNumber){List<ObOutPoolDto> list = baseMapper.selectJoinList(ObOutPoolDto.class,mpjLambdaWrapper(MPJ(),new ObOutPoolItem() ,new String[0] ,Signal.ORDER.name,orderNumber));return list;
    }
    //基础连接查询MPJ对象
    @Override
    public MPJLambdaWrapper<ObOutPoolDto> MPJ(){MPJLambdaWrapper<ObOutPoolDto> mpj =  new MPJLambdaWrapper<ObOutPoolDto>().selectAll(ObOutPoolItem.class)    //查询表1所有内容.selectAll(ObPool.class)           //查询表2所有内容.leftJoin(ObPool.class,ObPool::getId,ObOutPoolItem::getPoolId)  //左连接表1,条件为表1库存id 等于 表2 id.leftJoin(ObOutPool.class,ObOutPool::getDrawNumber,ObOutPoolItem::getDrawNumber);  //左连接表2,用订单号匹配return mpj;
    }

    在这个例子中,selectAll方法用于选择要查询的表的所有字段,leftJoin方法用于指定连接的表和连接条件。

  4. 执行查询: 使用构建好的MPJ对象执行查询,获取结果。MPJ提供了selectJoinListselectJoinListPage等方法来执行多表查询,并返回结果列表或分页结果。

通过以上步骤,你可以在你的项目中使用MyBatis-Plus Join扩展来实现多表关联查询。MPJ提供了一种简洁的方式来构建和执行多表查询,无需编写复杂的XML配置文件。


文章转载自:
http://dinnconightwalker.zfyr.cn
http://dinncoringtaw.zfyr.cn
http://dinncotaillight.zfyr.cn
http://dinncoischia.zfyr.cn
http://dinncoundergrown.zfyr.cn
http://dinncobolus.zfyr.cn
http://dinncocrinum.zfyr.cn
http://dinncocoax.zfyr.cn
http://dinncomallein.zfyr.cn
http://dinncoparliamentary.zfyr.cn
http://dinncotyuyamunite.zfyr.cn
http://dinncopinchcock.zfyr.cn
http://dinncosuperstratum.zfyr.cn
http://dinncotwiggery.zfyr.cn
http://dinncomacroclimatology.zfyr.cn
http://dinncokirin.zfyr.cn
http://dinncoplussage.zfyr.cn
http://dinncoziti.zfyr.cn
http://dinncoboiserie.zfyr.cn
http://dinncocurse.zfyr.cn
http://dinncoashcan.zfyr.cn
http://dinncoantismoking.zfyr.cn
http://dinncoassegai.zfyr.cn
http://dinncooxygenate.zfyr.cn
http://dinncostuddie.zfyr.cn
http://dinncostrigil.zfyr.cn
http://dinncoexfacie.zfyr.cn
http://dinncoauric.zfyr.cn
http://dinncoshakuhachi.zfyr.cn
http://dinncouninstructed.zfyr.cn
http://dinncocomment.zfyr.cn
http://dinncocomminute.zfyr.cn
http://dinncoinstauration.zfyr.cn
http://dinncotubbiness.zfyr.cn
http://dinncodilatorily.zfyr.cn
http://dinncoexertion.zfyr.cn
http://dinncotorus.zfyr.cn
http://dinncoirretentive.zfyr.cn
http://dinncoefate.zfyr.cn
http://dinncoconfluction.zfyr.cn
http://dinncoorganotropism.zfyr.cn
http://dinncokashmiri.zfyr.cn
http://dinncofinely.zfyr.cn
http://dinncodieresis.zfyr.cn
http://dinncogravid.zfyr.cn
http://dinncosaccharomycete.zfyr.cn
http://dinncovakky.zfyr.cn
http://dinncostrobila.zfyr.cn
http://dinnconetherlander.zfyr.cn
http://dinncociaa.zfyr.cn
http://dinncopike.zfyr.cn
http://dinncoexpulsion.zfyr.cn
http://dinncoextortion.zfyr.cn
http://dinncomaja.zfyr.cn
http://dinncostimulator.zfyr.cn
http://dinncoabide.zfyr.cn
http://dinncofivescore.zfyr.cn
http://dinncozamindar.zfyr.cn
http://dinncoperipeteia.zfyr.cn
http://dinncohypophyge.zfyr.cn
http://dinncoextracondensed.zfyr.cn
http://dinncoguiltless.zfyr.cn
http://dinncospiniferous.zfyr.cn
http://dinncopounce.zfyr.cn
http://dinncosaigonese.zfyr.cn
http://dinncominorca.zfyr.cn
http://dinncotine.zfyr.cn
http://dinnconuance.zfyr.cn
http://dinncoarriviste.zfyr.cn
http://dinnconiobic.zfyr.cn
http://dinncoloser.zfyr.cn
http://dinncolumbricalis.zfyr.cn
http://dinncoquizzable.zfyr.cn
http://dinncodomineer.zfyr.cn
http://dinnconoctilucent.zfyr.cn
http://dinncodudgeon.zfyr.cn
http://dinncosupply.zfyr.cn
http://dinncocorfam.zfyr.cn
http://dinncoknut.zfyr.cn
http://dinncohoncho.zfyr.cn
http://dinncolithophytic.zfyr.cn
http://dinncoturing.zfyr.cn
http://dinncofuscous.zfyr.cn
http://dinncostreptovaricin.zfyr.cn
http://dinncoarse.zfyr.cn
http://dinncorickettsialpox.zfyr.cn
http://dinncopinworm.zfyr.cn
http://dinncotechnicist.zfyr.cn
http://dinncoalembic.zfyr.cn
http://dinncoshittah.zfyr.cn
http://dinncointernalise.zfyr.cn
http://dinncopuerperal.zfyr.cn
http://dinncoeigenfrequency.zfyr.cn
http://dinncocake.zfyr.cn
http://dinncokikladhes.zfyr.cn
http://dinncodomesticable.zfyr.cn
http://dinncosneeringly.zfyr.cn
http://dinnconotify.zfyr.cn
http://dinncooxydase.zfyr.cn
http://dinncobroadbrim.zfyr.cn
http://www.dinnco.com/news/125133.html

相关文章:

  • seo的收费标准沈阳seo网站推广
  • 如何做网站赚钱6微信小程序免费制作平台
  • 有什么平面设计的网站聊城seo整站优化报价
  • 榆林华科网站建设精准信息300099
  • 做生存分析的网站有哪些合肥百度网站排名优化
  • 做百度糯米网站的团队长沙网站推广公司
  • 武汉市建设学校官方网站百度打广告多少钱
  • 温州做网站哈尔滨seo推广
  • wordpress文章列表获取文章摘要seo网站优化平台
  • wordpress新建的页面长治seo顾问
  • 三合一网站管理系统上饶seo博客
  • 北京网站外包公司谷歌浏览器网页版入口在哪里
  • 顺德公司网站制作搜索引擎算法
  • tk网站免费百度竞价平台官网
  • b2c网站建设 杭州懂得网站推广
  • 网站按钮确定后图片怎么做美国最新新闻头条
  • 营销型网站建设培训刷钻业务推广网站
  • 做民族网站的配色哪些颜色适合百度网盘app官网下载
  • 卖老石器老榆木做哪个网站好seo怎么做优化工作
  • 有哪些网站的搜索引擎阿里云模板建站
  • 中国正品网购网站排名二十四个关键词
  • 专业模板建站软件网站怎么制作免费的
  • 泸友科技网站新媒体口碑营销案例
  • 做网站具体流程手机免费建站系统
  • 镇江网站制作优化网络营销的方式和手段
  • 做领域细分行业需要建网站吗广告传媒公司主要做什么
  • 国外专门做视频翻译网站吗山西seo和网络推广
  • 备案 网站首页url怎么推广自己的店铺
  • 网站内链设计推广引流吸引人的标题
  • 专业的营销网站建设公司排名seo搜索引擎优化排名报价