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

政府网站有哪些怎样免费推广自己的网站

政府网站有哪些,怎样免费推广自己的网站,淘宝运营模式,个人备案可以做企业网站吗目录 一 对于映射的概念 1.1 三种关系映射 1.2 resultType与resultMap的区别 resultType: resultMap: 二,一对一关联查询 2.1 嵌套结果集编写 2.2 案例演示 三,一对多关联查询 3.1 嵌套结果集编写 3.3 案例演示 四&…

目录

一 对于映射的概念

1.1 三种关系映射

1.2 resultType与resultMap的区别

resultType:

resultMap:

二,一对一关联查询

2.1 嵌套结果集编写

2.2 案例演示

三,一对多关联查询

3.1 嵌套结果集编写

 3.3 案例演示

四,多对多关联查询 

4.1 嵌套结果集编写

 4.2 案例演示

一 对于映射的概念

     在关系型数据库中,表与表之间存在着三种关联映射关系,分别为一对一关系、一对多关系和多对多关系。  那在 MyBatis 中,通过 association 元素来处理对象与对象之间关联关系,association 元素提供了一系列属性用于维护数据表之间的关系。association 元素是 resultMap元素的子元素,它有两种配置方式,嵌套查询方式和嵌套结果集方式。

1.1 三种关系映射

一对一关联映射:

      这种关系表示两个实体类之间存在唯一的对应关系,通常通过在表之间使用外键来建立连接。在 MyBatis 中可以使用 association 元素来实现一对一关联映射

一对多关联映射:

     这种关系表示一个实体类关联多个其他实体类的实例。例如,在数据库中,一个文章可以对应多个评论。在 MyBatis 中可以使用 collection 元素来实现一对多关联映射

多对多关联映射:

         这种关系表示两个实体类之间存在多对多的关系,通常通过中间表来实现。例如,一个用户可以拥有多个角色,一个角色也可以被多个用户拥有。在 MyBatis 中可以使用中间表和联合查询来实现多对多关联映射。

1.2 resultType与resultMap的区别

resultType:

使用 resultType,我们直接指定了查询结果的类型,它通常用于简单的查询语句,不需要复杂的映射关系。优点是简单直观,缺点是不能进行复杂的映射操作(实体类没有该属性的情况)。

resultMap:

    而使用 resultMap,我们可以更加灵活地映射查询结果到任意类型的 Java 对象上。通过定义一个 resultMap,我们可以指定每个查询结果列与 Java 对象属性之间的映射关系。优点是功能强大,可以进行各种复杂的映射操作,缺点是需要编写更多的 XML 配置代码

二,一对一关联查询

这里需要建一个VO类,VO是Value Object的缩写,是一轻量级的数据结构,用于在视图层与业务逻辑层之间传递数据。VO通常用于表示视图层所需的数据,这些数据来自于业务逻辑层或数据访问层。VO的主要目的是将业务逻辑层的数据结构转换为视图层可以使用的数据结构 。简单来说就是用于关系映射时的结果接收

下面我们利用订单项以及订单来描述一对一的关系,所以我们建立一个OrderitemVo

OrderitemVo:

public class OrderitemVo extends Orderitem {private Order order;public Order getOrder() {return order;}public void setOrder(Order order) {this.order = order;}

2.1 嵌套结果集编写

<resultMap id="OrderitemvoMap" type="com.Bing.vo.OrderitemVo"><result column="order_item_id" property="orderItemId"></result><result column="product_id" property="productId"></result><result column="quantity" property="quantity"></result><result column="oid" property="oid"></result><association property="order" javaType="com.Bing.model.Order"><result column="order_id" property="orderId"></result><result column="order_no" property="orderNo"></result></association></resultMap><select id="selectByOiid" resultMap="OrderitemvoMap" parameterType="java.lang.Integer">select * from t_hibernate_order o,t_hibernate_order_item oi where o.order_id=oi.oid and oi.order_item_id=#{oiid}</select>

2.2 案例演示

接口类并实现

接口Biz编写:

public interface OrderitemBiz {OrderitemVo selectByOiid(Integer oiid);
}

实现类Impl类继承Biz:

@Service
public class OrderitemImpl implements OrderitemBiz {@Autowiredprivate OrderitemMapper OrderitemMapper;@Overridepublic OrderitemVo selectByOiid(Integer oiid) {return OrderitemMapper.selectByOiid(oiid);}
}

Test类编写:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-context.xml"})
public class OrderitemImplTest {@Autowiredprivate OrderitemBiz OrderitemBiz;@Testpublic void selectByOiid() {OrderitemVo orderitemVo = OrderitemBiz.selectByOiid(27);System.out.println(orderitemVo);System.out.println(orderitemVo.getOrder());}
}

测试运行结果:

三,一对多关联查询

下面我们利用订单以及订单项来描述一对多的关系,所以我们建立一个OrderVo。

注意:要使用list集合

public class OrderVo extends Order {private List<Orderitem> orderitems=new ArrayList<>();public List<Orderitem> getOrderitems() {return orderitems;}public void setOrderitems(List<Orderitem> orderitems) {this.orderitems = orderitems;}@Overridepublic String toString() {return "OrderVo{" +"orderitems=" + orderitems +'}';}
}

3.1 嵌套结果集编写

 <resultMap id="OrderMap" type="com.Bing.vo.OrderVo" ><result column="order_id" property="orderId"></result><result column="order_no" property="orderNo"></result><collection property="orderitems" ofType="com.Bing.model.Orderitem"><result column="order_item_id" property="orderItemId"></result><result column="product_id" property="productId"></result><result column="quantity" property="quantity"></result><result column="oid" property="oid"></result></collection></resultMap><select id="byOid" resultMap="OrderMap" parameterType="java.lang.Integer" >select * from t_hibernate_order o,t_hibernate_order_item oi where o.order_id=oi.oidand o.order_id=#{oid}</select>

 3.3 案例演示

接口类并实现

接口Biz编写:

public interface OrderBiz {OrderVo byOid(Integer id);
}

实现Impl类继承Biz:

@Service
public class OrderBizImpl implements OrderBiz {@Autowiredprivate OrderMapper orderMapper;@Overridepublic OrderVo byOid(Integer id) {return orderMapper.byOid(id);}
}

Test类编写:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-context.xml"})
public class OrderBizImplTest {
@Autowired
private OrderBiz orderBiz;@Testpublic void byOid() {OrderVo orderVo = orderBiz.byOid(7);System.out.println(orderVo);orderVo.getOrderitems().forEach(System.out::println);}
}

测试类运行结果:

四,多对多关联查询 

我们以书籍有多个类别以及每个类别又有多本书的这种关系来实操多对多关系的查询

HbookVo:

public class HbookVo  extends HBook {private List<HCategory> hcategory;public List<HCategory> getHcategory() {return hcategory;}public void setHcategory(List<HCategory> hcategory) {this.hcategory = hcategory;}
}

4.1 嵌套结果集编写

<resultMap id="HbookVo" type="com.Bing.vo.HbookVo" ><result column="book_id" property="bookId"></result><result column="book_name" property="bookName"></result><result column="price" property="price"></result><collection property="hcategory" ofType="com.Bing.model.HCategory"><result column="category_id" property="categoryId"></result><result column="category_name" property="categoryName"></result></collection></resultMap><select id="selectByBid" resultMap="HbookVo" parameterType="java.lang.Integer">SELECT*
FROMt_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c
WHEREb.book_id = bc.bidAND bc.cid = c.category_idAND b.book_id =#{bid}</select>

 4.2 案例演示

接口类并实现

接口Biz编写:

public interface HBookBiz {HbookVo selectByBid(Integer bid);
}

实现类Impl类继承Biz:

@Service
public class HBookBizImpl implements HBookBiz {@Autowiredprivate HBookMapper hbookMapper;@Overridepublic HbookVo selectByBid(Integer bid) {return hbookMapper.selectByBid(bid);}
}

Test类编写:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-context.xml"})
public class HBookBizImplTest {@Autowiredprivate HBookBiz hbookBiz;@Testpublic void selectByBid() {HbookVo hbookVo = hbookBiz.selectByBid(8);System.out.println(hbookVo);hbookVo.getHcategory().forEach(System.out::println);}
}

Test类运行结果:

                                好啦,今天的分享就到这了,希望能够帮到你呢!😊😊   

http://www.khdw.cn/news/34328.html

相关文章:

  • 牟平网站建设武汉关键词seo
  • 网站后台用什么程序做谷歌广告优化师
  • 自己建网站卖东西怎么样品牌推广方案包括哪些
  • wordpress浏览数插件引擎优化seo
  • 西安有没有网站建设和营销的培训百度公司电话
  • wordpress幻灯片代码福州seo顾问
  • 短视频矩阵营销seo培训学院
  • windows主机 wordpress 防盗链潍坊seo建站
  • 绍兴做网站哪家好搜索引擎推广方案
  • 广州网站开发 细致广州亦客网络网络营销的核心是什么
  • 网站建设云主机云服务器外贸软件
  • 怎么做电影网站的微信seo是什么意思
  • 优秀的移动端网站福州seo代理商
  • 公司网站设网络广告推广服务
  • 东莞网站建设中企动力技术支持今天晚上19点新闻联播直播回放
  • 北京网站建设有限公司清远seo
  • 珠海做企业网站多少钱外包公司是正规公司吗
  • 江西赣州网络公司合肥seo网站排名
  • 确定网站建设目的成都网站关键词推广优化
  • 安徽哪些地方封城了整站seo外包
  • 动态网站建设步骤淘宝搜索排名
  • 做平面什么网站好用网站安全检测工具
  • 网站模板整站资源网络营销公司好不好
  • 怎样把自己的网站上传百度官网下载
  • 只做动漫的h网站百度客服在线咨询人工服务
  • app下载登录郑州seo顾问外包公司
  • 馆陶做网站以图搜图百度识图网页版
  • 做ug图纸的网站百度竞价托管公司
  • 重庆九龙坡区哪里有做网站的域名注册时间查询
  • 阿里云做网站流程活动推广