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

小米路由HD可以做网站吗seo免费入门教程

小米路由HD可以做网站吗,seo免费入门教程,怎么设计网站内容,手机网站 域名解析一对多关联映射 一对多关联映射有两种方式,都用到了collection元素 以购物网站中用户和订单之间的一对多关系为例 collection集合的嵌套结果映射 创建两个实体类和映射接口 package org.example.demo;import lombok.Data;import java.util.List;Data public cla…

一对多关联映射

一对多关联映射有两种方式,都用到了collection元素

以购物网站中用户和订单之间的一对多关系为例

collection集合的嵌套结果映射

创建两个实体类和映射接口

package org.example.demo;import lombok.Data;import java.util.List;@Data
public class User {private Integer userId;private String userName;private String password;private Cart cart;private List<Order> orderList;
}
package org.example.demo;import lombok.Data;@Data
public class Order {private Integer orderId;private double price;
}

实现根据用户id查询出所有用户信息,包括该用户的所有订单信息 

package org.example.mapper;import org.example.demo.User;import java.util.List;public interface UserMapper {User findUserAndOrderListByUserId(Integer userId);
}
方式一:与association类似,集合的嵌套结果映射就是指通过一次SQL查询得到所有的结果 
<resultMap type="com.mybatis.entity.User" id="userMap"><id property="id" column="id"/><result property="userName" column="user_name"/><result property="password" column="password"/>
</resultMap>
<resultMap type="com.mybatis.entity.User" id="userAndOrderListMap" extends="userMap"><collection property="orderList" ofType="com.mybatis.entity.Order"><id property="id" column="order_id"/><result property="price" column="price"/></collection>
</resultMap>
<select id="findUserAndOrderListById" resultMap="userAndOrderListMap">select u.id, u.user_name, u.password,o.order_id, o.pricefrom user uleft join orders o on u.id = o.user_idwhere u.id = #{id}
</select>

resultMap元素中的extends属性可以实现结果映射的继承

collection的ofType属性指定集合中元素的类型,必选项 

    <resultMap id="userAndOrderMap" type="org.example.demo.User"><id property="userId" column="user_id"/><result property="userName" column="user_name"/><result property="password" column="password"/><collection property="orderList" ofType="org.example.demo.Order"><id property="orderId" column="order_id"/><result property="price" column="price"/></collection></resultMap><select id="findUserAndOrderListByUserId" resultMap="userAndOrderMap">select*from t_user uleft join t_order o on u.user_id = o.user_idwhere u.user_id = #{userId};</select>

 

collection集合的嵌套查询

集合的嵌套查询同样会执行额外的SQL查询

<resultMap type="com.mybatis.entity.User"id="userAndOrderListMap" extends="userMap"><collection property="orderList" column="{uid=id}"ofType="com.mybatis.entity.Order"       select="com.mybatis.mapper.OrderMapper.findOrdersByUserId"></collection>
</resultMap>
<select id="findUserAndOrderListById" resultMap="userAndOrderListMap">select * from user where id = #{id}
</select>

OrderMapper.xml

<resultMap type="com.mybatis.entity.Order"id="orderMap"><id property="id" column="order_id"/><result property="price" column="price"/>
</resultMap>
<select id="findOrdersByUserId"resultMap="orderMap">select * from orders where user_id = #{uid}
</select>

对比两种方式

第一种方式属于“关联的嵌套结果映射“,即通过一次SQL查询根据表或指定的属性映射到不同的对象中

第二种方式属于“关联的嵌套查询”,利用简单的SQL语句,通过多次查询得到想要的结果,也可以实现延迟加载效果 

 

 

http://www.zhongyajixie.com/news/62791.html

相关文章:

  • 公司网站建设系统互联网营销方案
  • 网站建设公司哪家好 搜搜磐石网络nba最新比赛直播
  • 购物网站有哪些模块流量推广app
  • 小说网站开发数据库深圳网站制作
  • flash做网站网站seo优化方案项目策划书
  • 东台专业做网站的公司泰安网站优化公司
  • 网站轮播动态图如何做在线资源搜索神器
  • 网站建设流程共有几个阶段资深seo顾问
  • 浩森宇特北京网站建设微信营销推广公司
  • 电商网站建设济南建网站子域名网址查询
  • 知乎网站建设用的工具郑州百度seo网站优化
  • 常用的网站类型有哪些类型有哪些优化防疫措施
  • 淄博建设网站公司会计培训班的费用是多少
  • 自己做的小说网站要交税吗百度助手手机下载
  • wordpress 物流信息合肥网络公司seo建站
  • 有哪些网站可以做按摩广告深圳优化公司样高粱seo
  • 网站里的动效怎么做引擎优化搜索
  • 请人做网站多少钱链接买卖价格
  • 网站建设在哪能看培训如何优化网站
  • wordpress评论改成微博落实好疫情防控优化措施
  • 推广企业网站最主要的方式是广告的六种广告形式
  • 学什么可以先做网站天津seo诊断技术
  • 朝阳区手机网站设计服务线上网络推广怎么做
  • 网站制作公司哪家好全球网站排名查询
  • wordpress 百度商桥西安seo高手
  • 163k系统功能介绍桂平seo快速优化软件
  • 集团网站策划北京seo排名技术
  • 邯郸网站建设有哪些推广策略
  • 做网站运营需要什么证热门推广软件
  • 民权网站建设如何做好互联网营销推广