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

网站实名制认证备案最新seo网站优化教程

网站实名制认证备案,最新seo网站优化教程,腾讯云服务器centos做静态网站,一二三四视频社区关系映射 参考文档复习#xff1a;1对1#xff0c;1对多#xff0c;多对多 1.映射(多)对一、(一)对一的关联关系 1).使用列的别名 ①.若不关联数据表#xff0c;则可以得到关联对象的id属性 ②.若还希望得到关联对象的其它属性。则必须关联其它的数据表 … 关系映射   参考文档复习1对11对多多对多      1.映射(多)对一、(一)对一的关联关系    1).使用列的别名     ①.若不关联数据表则可以得到关联对象的id属性     ②.若还希望得到关联对象的其它属性。则必须关联其它的数据表      1.创建表    员工表    DROP TABLE IF EXISTS tbl_employee; CREATE TABLE tbl_employee (     id int(11) NOT NULL AUTO_INCREMENT,     user_name varchar(255) DEFAULT NULL,     gender char(1) DEFAULT NULL,     email varchar(255) DEFAULT NULL,     d_id int(11) DEFAULT NULL,     PRIMARY KEY (id),     KEY fk_emp_dept (d_id),     CONSTRAINT fk_emp_dept FOREIGN KEY (d_id) REFERENCES tbl_dept (id)) ENGINEInnoDB AUTO_INCREMENT5 DEFAULT CHARSETutf8;         部门表    CREATE TABLE tbl_dept(      id INT(11) PRIMARY KEY AUTO_INCREMENT,      dept_name VARCHAR(255)   )       2.创建相应的实体类和Mapper接口!     3.写关联的SQL语句    SELECT e.id id , e.user_name user_name, e.gender gender,e.d_id d_id,d.id did,d.dept_name dept_name    FROM tbl_employee e, tbl_dept d    WHERE e.d_id d.id AND e.id 1   4.在sql映射文件中写映射sql语句【联合查询级联属性封装结果集】      !-- 联合查询级联属性封装结果集 --    resultMap typecom.neuedu.entity.Employee idgetEmployeeAndDeptMap     id columnid propertyid/     result columnuser_name propertyuserName/     result columngender propertygender/     result columnemail propertyemail/     result columndid propertydepart.id/     result columndept_name propertydepart.deptName/    /resultMap       !-- public Employee getEmployeeAndDept(Integer id); --    select idgetEmployeeAndDept resultMapgetEmployeeAndDeptMap     SELECT e.id id , e.user_name user_name, e.gender gender,e.email email,e.d_id d_id,d.id did,d.dept_name dept_name     FROM tbl_employee e, tbl_dept d     WHERE e.d_id d.id AND e.id #{id}    /select          注意即使使用resultMap来映射对于“对一”关联关系可以不使用association      5.编写测试用例    方法二【使用association来定义关联对象的规则,[比较正规的推荐的方式]】       !-- 联合查询使用association封装结果集 --    resultMap typecom.neuedu.entity.Employee idgetEmployeeAndDeptMap     id columnid propertyid/     result columnuser_name propertyuserName/     result columngender propertygender/     result columnemail propertyemail/     !--     association可以指定联合的javaBean对象     propertydepart:指定哪个属性是联合的对象     javaType:指定这个属性对象的类型【不能省略】     --     association propertydepart javaTypecom.neuedu.entity.Department      id columndid propertyid/      result columndept_name propertydeptName/     /association    /resultMap       !-- public Employee getEmployeeAndDept(Integer id); --    select idgetEmployeeAndDept resultMapgetEmployeeAndDeptMap     SELECT e.id id , e.user_name user_name, e.gender gender,e.email email,e.d_id d_id,d.id did,d.dept_name dept_name     FROM tbl_employee e, tbl_dept d     WHERE e.d_id d.id AND e.id #{id}    /select         方法三[上述结果相当于使用嵌套结果集的形式]【我们这里还可以使用Association进行分步查询】       !--    使用association进行分步查询      1.先按照员工id查询员工信息      2.根据查询员工信息中d_id值取部门表查出部门信息      3.部门设置到员工中:      -- select idgetDepartById resultTypecom.neuedu.entity.Department     SELECT id ,dept_name deptName FROM tbl_dept WHERE id #{id}    /select    resultMap typecom.neuedu.entity.Employee idmyEmpByStep     id columnid propertyid/     result columnuser_name propertyuserName/     result columngender propertygender/     result columnemail propertyemail/     !--     association定义关联对象的封装规则     select:表明当前属性是调用指定的方法查出的结果     column:指定将哪一列的值传给这个方法          流程使用select指定的方法(传入column指定的这列参数的值)查出对象并封装给property指定的属性。     --     association propertydepart selectgetDepartById columnd_id/association    /resultMap    !-- public Employee getEmpAndDept(Integer id); --    select idgetEmpAndDept resultMapmyEmpByStep     select * from tbl_employee where id #{id}    /select       补充懒加载机制【按需加载也叫懒加载】     !--   在分步查询这里我们还要讲到延迟加载   Employee  Dept:   我们每次查询Employee对象的时候都将关联的对象查询出来了。    而我们想能不能我在需要部门信息的时候再去查询不需要的时候就不用查询了。    答案可以的   我们只需要在分步查询的基础之上加上两个配置    1.在mybatis的全局配置文件中加入两个属性      settings      setting namemapUnderscoreToCamelCase valuetrue/      !-- 开启懒加载机制 ,默认值为true--      setting namelazyLoadingEnabled valuetrue/      !-- 开启的话每个属性都会直接全部加载出来禁用的话只会按需加载出来 --      setting nameaggressiveLazyLoading valuefalse/     /settings    测试        Test     public void testGetEmployee(){      EmployeeMapperPlus mapper openSession.getMapper(EmployeeMapperPlus.class);      Employee employee mapper.getEmpAndDept(1);      System.out.println(employee.getUserName());     }       此时可以看到这里只发送了一条SQL语句。         注意:上面我们上面如果关联的是一个对象我们还可以使用association标签如果我们关联的是一个集合     那么该使用谁呢      映射对多的关联关系   场景二查询部门的时候将部门对应的所有员工信息也查询出来注释在DepartmentMapper.xml中      第一种 1.修改Department实体类【添加Employee集合并为该集合提供getter/setter方法】      public class Department {       private Integer id;       private String deptName;             private ListEmployee list;             public ListEmployee getList() {        return list;       }       public void setList(ListEmployee list) {        this.list list;       }      ......      }           建立DepartmentMapper接口文件并添加如下方法       public Department getDeptByIdPlus(Integer id);            2.sql映射文件中的内容为【collection:嵌套结果集的方式使用collection标签定义关联的集合类型元素的封装规则】       !-- public Department getDeptByIdPlus(Integer id); --       resultMap typecom.neuedu.entity.Department idgetDeptByIdPlusMap       id columndid propertyid/       result columndept_name propertydeptName/       !--       collection:定义关联集合类型的属性的封装规则       ofType:指定集合里面元素的类型       --       collection propertylist ofTypecom.neuedu.entity.Employee        !-- 定义这个集合中元素的封装规则 --        id columneid propertyid/        result columnuser_name propertyuserName/        result columnemail propertyemail/        result columngender propertygender/       /collection       /resultMap             select idgetDeptByIdPlus resultMapgetDeptByIdPlusMap       SELECT d.id did, d.dept_name dept_name,e.id eid,e.user_name user_name,e.email email,e.gender gender       FROM tbl_dept d       LEFT JOIN tbl_employee e       ON e.d_id d.id       WHERE d.id #{id}       /select           3.测试方法为      Test      public void testGetEmployee(){       DepartmentMapper mapper openSession.getMapper(DepartmentMapper.class);       Department department mapper.getDeptByIdPlus(2);       System.out.println(department);      }  第二种使用分步查询结果集的方式    1.如果使用分步查询的话我们的sql语句就应该为             SELECT * FROM tbl_dept WHERE id 2;     SELECT * FROM tbl_employee WHERE d_id 2;          2.在DepartmentMapper接口文件中添加方法,如下所示     public Department getDeptWithStep(Integer id);        3.再从EmployeeMapper接口中添加一个方法如下所示     public ListEmployee getEmployeeByDeptId(Integer deptId);     并在响应的sql映射文件中添加相应的sql语句      select idgetEmployeeByDeptId resultTypecom.neuedu.entity.Employee       select * from tbl_employee where d_id #{departId}      /select     4.在DepartmentMapper映射文件中     resultMap typecom.neuedu.entity.Department idgetDeptWithStepMap      id columnid propertyid/      result columndept_name propertydeptName/      collection propertylist  selectcom.neuedu.mapper.EmployeeMapper.getEmployeeByDeptId columnid /collection      /resultMap      select idgetDeptWithStep resultMapgetDeptWithStepMap       SELECT id ,dept_name FROM tbl_dept WHERE id #{id}      /select         5.测试类     Test     public void testGetEmployee(){      DepartmentMapper mapper openSession.getMapper(DepartmentMapper.class);      Department department mapper.getDeptWithStep(2);      System.out.println(department);     }         总结 1.映射(一)对多、(多)对多的关联关系》【映射对多的关联关系】    2.必须使用collection节点进行映射     3.注意ofType指定集合中的元素类型           4.!--        collection标签       映射多的一端的关联关系使用ofType指定集合中的元素类型      columnprefix:指定列的前缀      使用情境若关联的数据表和之前的数据表有相同的列名此时就需要给关联的列其别名.      若有多个列需要起别名可以为所有关联的数据表的列都加上相同的前缀然后再映射时指定前缀。     --  转载于:https://www.cnblogs.com/12344321hh/p/7481965.html
http://www.yutouwan.com/news/247042/

相关文章:

  • 柳州专业网站建设加盟惠州seo排名收费
  • 渭南建设用地规划查询网站建筑资质人才网官网
  • mvc做网站用的多不多wordpress用户绑定手机
  • 个人网站建设yxhuying个人网站收款
  • 池州网站制作优化电信网络服务商
  • 宁波自主建站模板投标网站建设
  • 安徽伟诚建设工程有限公司网站百度趋势搜索大数据
  • 怎样做化妆品网站服务外包有哪些
  • 网站seo基础优化python网站开发教程
  • 个人接单做网站的平台社交网站备案
  • 设计一个企业网站多少钱页面跳转不了怎么回事
  • 网站安全检测发生告警后网站建设 运维 管理包括
  • 南和网站建设公司做房地产网站
  • 网络技术培训内容网站如何做seo推广方案
  • 简述电子商务网站建设流程赚钱做任务的网站
  • 个人建站提供软件下载苏州建设工程公司
  • ppt做的好的网站有哪些wordpress如何自定义导航栏
  • 广州网站建设 推广公司哪家好做一个手机app大概需要多少钱
  • 商务网站规划与建设心得个人兴趣网站设计
  • html5 珠宝网站广东省自然资源厅吴鋆
  • 官网查询网站智慧旅游网站建设方案ppt
  • 网站建设需要考哪些证外贸购物网站制作
  • 网站硬件费用陕西建设部网站官网
  • 最出名的网站建设公司学历提升
  • 国外网站 icp备案广告设计好找工作吗
  • 系部网站开发项目的目的邯郸网站建设选哪家
  • 本地扬中网站建设wordpress阅读数 显示k
  • 建设一个网站需要做哪些事情钦州网站建设公司
  • 外贸网站建设软件有哪些知乎seo排名帝搜软件
  • 做新零售这些注册网站和找货源做纺织的用什么网站