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

购物网网站建设lamp 做网站

购物网网站建设,lamp 做网站,太平洋网站开发,wordpress工坊一对一映射 预置条件 在某网络购物系统中#xff0c;一个用户只能拥有一个购物车#xff0c;用户与购物车的关系可以设计为一对一关系 数据库表结构#xff08;唯一外键关联#xff09; 创建两个实体类和映射接口 package org.example.demo;import lombok.Data;import … 一对一映射 预置条件 在某网络购物系统中一个用户只能拥有一个购物车用户与购物车的关系可以设计为一对一关系 数据库表结构唯一外键关联  创建两个实体类和映射接口  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 ListOrder orderList; } package org.example.demo;import lombok.Data;Data public class Cart {private Integer cartId;private double price; } 实现根据用户id查询出所有用户信息包括该用户的购物车信息  package org.example.mapper;import org.example.demo.User;import java.util.List;public interface UserMapper {User findUserAndCartByUserId(Integer userId); } MyBatis中处理一对一关联关系的方法有四种 使用自动映射处理一对一关系 使用自动映射处理一对一关系也就是通过别名自动将值匹配到对应的字段上  ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespaceorg.example.mapper.UserMapperselect idfindUserAndCartByUserId resultTypecom.mybatis.entity.Userselect*from t_user uinner join t_cart c on u.user_id c.user_idwhere u.user_id #{userId};/select /mapper 复杂的属性映射时可以多层嵌套比如将cart表中的cart_id字段映射到Cart.id属性上  使用resultMap配置一对一映射 使用这种方式同自动映射方式相似之处为Cart中的属性配置部分使用了”Cart.”前缀 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespaceorg.example.mapper.UserMapper resultMap iduserMap typeorg.example.demo.Userid propertyuserId columnuser_id/result propertyuserName columnuser_name/result propertypassword columnpassword/result propertycart.cartId columncart_id/result propertycart.price columnprice//resultMap select idfindUserAndCartByUserId resultMapuserMapselect*from t_user uinner join t_cart c on u.user_id c.user_idwhere u.user_id #{userId};/select /mapper 使用association元素配置一对一映射 association元素用于和一个复杂的类型进行关联 association元素包含以下属性 property对应实体类中的属性名必填项 javaType属性对应的java类型可选项 resultMap可以直接使用现有的resultMap而不需要在这里配置可选项 resultMap iduserMap typeorg.example.demo.Userid propertyuserId columnuser_id/result propertyuserName columnuser_name/result propertypassword columnpassword/association propertycartid propertycartId columncart_id/result propertyprice columnprice//association/resultMapselect idselectUserById resultMapuserMapselect * from t_user where user_id #{userId};/select association元素的嵌套查询 association元素的嵌套查询常用的属性如下 select另一个查询映射的statement idMyBatis会额外执行这个查询获取嵌套对象 column列名将主查询中列的结果作为嵌套查询的参数column“{prop1col1,prop2col2}”其中prop1和prop2将作为嵌套查询的参数 fetchType数据加载方式可选值为lazy和eager分别为延迟加载和积极加载会覆盖全局的lazyLoadingEnable配置 resultMap iduserMap typeorg.example.demo.Userid propertyuserId columnuser_id/result propertyuserName columnuser_name/result propertypassword columnpassword/association propertycart columnuser_id selectfindCartbyUserIdfetchTypelazy//resultMapresultMap idcartMap typeorg.example.demo.Cartid propertycartId columncart_id/result propertyprice columnprice//resultMapselect idfindUserAndCartByUserId resultMapuserMapselect * from t_suer u where user_id #{user_id};/selectselect idfindCartbyUserId resultMapcartMapselect * from t_cart c where c.user_id #{user_id};/select 嵌套查询会多执行SQL当查询N条数据时就会出现N1次查询问题 为了解决N1次查询问题可以设置延迟加载策略将association元素的fetchType属性设置为lazy  设置为延迟加载的对象默认情况下当调用该对象的equals、hashCode、toString、clone方法时就会加载该对象的全部数据 对比四种方式 前面的三种方式都属于“关联的嵌套结果映射“,即通过一次SQL查询根据表或指定的属性映射到不同的对象中 最后一种方式属于“关联的嵌套查询”利用简单的SQL语句通过多次查询得到想要的结果可实现延迟加载效果
http://www.w-s-a.com/news/730935/

相关文章:

  • 做网站网站庄家html5网站开发技术
  • 无锡门户网站制作电话广告设计公司的未来
  • 白云区专业网站建设网页设计模拟试题答案
  • 毕业设计网站代做多少钱制作旅游网站设计概述
  • 网站开发维护运维无人在线电视剧免费观看
  • 电子商务网站建设开题报告展馆网站建设
  • 门户网站建设的背景和意义手机网站前
  • 国内免费视频素材无水印素材网站国家最新消息
  • 襄阳seo站内优化学做网站论坛教程
  • 文明网站建设情况报告wordpress伪静态配置
  • 牙科网站模板个人微信网站建设
  • 厦门公司注册网站dw做简单小说网站
  • 网站建好以后每年都续费么wordpress 仿聚划算
  • 单位网站建设收费标准网上开店铺需要多少钱
  • 灯饰网站需要这么做申请域名的流程
  • 软件下载网站怎么赚钱wordpress减少数据库查询
  • 什么兼职网站可以做视频剪辑常见的推广平台有哪些
  • 网站开发是用html还是jsp设迹官网
  • 查公司信息的网站怎么学wordpress
  • 白银做网站长春一般建一个网站需要多少钱
  • 帮人做钓鱼网站的人网络推广培训职业学校
  • 淘宝客有必须做网站吗网站开发的形式有( )
  • 网站建设:上海珍岛网页版qq空间登录
  • 网站服务器ipteahouse wordpress主题
  • 深州市住房保障和城乡建设局网站做网站公司叫什么
  • 织梦网站转跳手机站注册公司代理记账费用
  • wordpress建站Pdf亚马逊aws在线观看
  • 做网站的外包公司有哪些WordPress调用json数据
  • 做网站网站怎么赚钱网站的建设及维护报告
  • 可以做效果图的网站东莞网站优化什么方法