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

做响应式网站多少钱做论坛app网站有哪些

做响应式网站多少钱,做论坛app网站有哪些,网站视频背景怎么做,wordpress免邮箱验证文章目录 多表查询一对一一对多 多表查询 一对一 开启代码片段编写 专注于 SQL的 编写 JDBC 的写法,注重于 SQL mybatis 在 一对一查询时,核心在于 建立每个表对应的实体类主键根据 主键 id 进行查询,副标根据 设定外键进行查询 在 SQL编写…

文章目录

    • 多表查询
      • 一对一
      • 一对多

多表查询

一对一

  • 开启代码片段编写

image-20250406211401870

image-20250406211421125

专注于 SQL的 编写

  • JDBC 的写法,注重于 SQL

image-20250406212503288

  • mybatis 在 一对一查询时,核心在于
    • 建立每个表对应的实体类
    • 主键根据 主键 id 进行查询,副标根据 设定外键进行查询 在 SQL编写上简单很多
    • 通过注解,对映射结果进行处理,让二者产生联系,来实现多表查询

image-20250406213406652

  • 学生详情实体类
package com.yanyu.mybatis2.po;import lombok.Data;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 21:26* @description:student_detail 表的 字段映射实体类*/
@Data
public class StudentDetail {private Integer id;private Integer studentId;private String addr;
}
  • 学生实体类
package com.yanyu.mybatis2.po;import lombok.Data;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 21:25* @description:student 表的 字段映射实体类*/
@Data
public class Student {private Integer id;private String name;private String stuid;private String major;
//  连接  学生详情的字段StudentDetail studentDetail;}
  • 接口设计
    • 分别编写查询student student_detail 的操作,根据 各自的主键 id
    • 处理映射结果集

image-20250406220831138

package com.yanyu.mybatis2.mapper;import com.yanyu.mybatis2.po.Student;
import com.yanyu.mybatis2.po.StudentDetail;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 21:39* @description:多表查询,一对一*/
public interface StudentOneToOne {
//    根据  id  主键  查询 副标 学生详情 结果自然就是  StudentDetail@Select("""select id,student_id,addr from student_detail where student_id=#{student_id}""")
//    进行副表的结果映射@Results({@Result(id = true,column = "id",property = "id"),@Result(column = "student_id",property = "studentId"),@Result(column = "addr",property = "addr")})StudentDetail selectStudentDetail(Integer student_id);//注意开启驼峰(appllication.properties)
//    根据 主表的 主键  id 进行  查询、@Select("""select id,name,stuid,major from student where id=#{id}""")
//    映射结果@Results({@Result(id = true,column = "id",property = "id"),@Result(column = "name",property = "name"),@Result(column = "stuid",property = "stuid"),@Result(column = "major",property = "stuid"),@Result(column = "id",property = "studentDetail",one = @One(select = "com.yanyu.mybatis2.mapper.StudentOneToOne.selectStudentDetail",fetchType = FetchType.LAZY))
//            将主表 student  的主键 id  作为  参数传递到  副表查询 的  方法中,本质 :  student.id = student_detail.student_id})Student selectStudent(Integer id);/** FetchType.LAZY 的作用
延迟加载(Lazy Loading):当设置为 FetchType.LAZY 时,关联的实体或集合不会在主实体被加载时立即加载。相反,它们会在真正需要访问这些关联数据时才被加载。
* 这种策略可以减少数据库查询的次数,提高性能,尤其是在关联数据量较大时。
按需加载:只有在访问关联属性时,Hibernate 才会发起额外的数据库查询来加载这些数据。
对比 FetchType.EAGER
FetchType.EAGER:表示立即加载。当主实体被加载时,关联的实体或集合也会被立即加载。这种策略适用于关联数据量较小且经常需要一起使用的场景,但可能会导致性能问题
* ,尤其是在关联数据量较大或关联关系较复杂时。
FetchType.LAZY:表示延迟加载。只有在真正需要访问关联数据时才会加载,适用于关联数据量较大或关联关系较复杂的情况,可以有效减少不必要的数据库查询。* */
}

image-20250406221128414

一对多

image-20250406222822632

  • 与一对一类似
    • 主表根据 id 查,副表根据 student_id 查
    • 副表映射的每个实体类都是一个对象,以集合形式出现在 主表的实体类中
package com.yanyu.mybatis2.po;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 22:32* @description:课程实体类*/
@Data
public class Course {private Integer id;private Integer studentId;private String name;
//  一个学生对应多个 课程,课程以集合形式出现在  学生类中}
package com.yanyu.mybatis2.po;import lombok.Data;import java.util.List;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 22:34* @description:学生与课程*/
@Data
public class StudentCourse {private Integer id;private String name;private String stuid;private String major;private List<Course> courses;
}
package com.yanyu.mybatis2.mapper;import com.yanyu.mybatis2.po.Course;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;import java.util.List;/*** @Author yanyu666_508200729@qq.com* @Date 2025/4/6 22:37* @description:*/
public interface StudentCourse {
//    根据  student_id 查课程 并 按 副表   主键  id 进行分组@Select("""select id,student_id,name from coursewhere student_id = #{student_id}order by id""")@Results(id = "studentCourse",value = {@Result(id = true, column = "id", property = "id"),@Result(column = "student_id", property = "studentId"),@Result(column = "name", property = "name")})List<Course> selectCourse(Integer student_id);
//    主表@Select("""select id,name,stuid,major from studentwhere id = #{id}""")@Results({@Result(id = true,column = "id",property = "id"),@Result(column = "name",property = "name"),@Result(column = "stuid",property = "stuid"),@Result(column = "major",property = "major"),@Result(column = "id",property = "courses",many = @Many(select = "com.yanyu.mybatis2.mapper.StudentCourse.selectCourse",fetchType = FetchType.LAZY))
//            将主表 student  的主键 id  作为  参数传递到  副表查询 的  方法中,本质 :  student.id = course.student_id})com.yanyu.mybatis2.po.StudentCourse selectStudentCourse(Integer id);}
  • 调错:看得懂就看(cause caused by),看不到,直接把错误复制,百度

image-20250406232036742

image-20250406232940467

  • 注意接口名和实体类名一样时,要特别留意 包名

image-20250406233241320

小结:

  • 各自查询各自的,然后再利用 one = @one many = @Many 进行关联

文章转载自:

http://GAmeot9S.bccLs.cn
http://W7rYlZkM.bccLs.cn
http://p8kHA4Dj.bccLs.cn
http://N33VxaVq.bccLs.cn
http://xukW862c.bccLs.cn
http://LNo1UObP.bccLs.cn
http://Ch24w4VQ.bccLs.cn
http://3bB7dotj.bccLs.cn
http://tSARBmiQ.bccLs.cn
http://BLqpzbAX.bccLs.cn
http://FX4VSleR.bccLs.cn
http://tZDDmpNS.bccLs.cn
http://VHyZ1QBa.bccLs.cn
http://hFrvN8Ga.bccLs.cn
http://oevqBWod.bccLs.cn
http://EhK4ZUXW.bccLs.cn
http://IAb1I25L.bccLs.cn
http://pokjmWWT.bccLs.cn
http://UbE1qEPL.bccLs.cn
http://zNjiwtSv.bccLs.cn
http://7XPKyrVk.bccLs.cn
http://ohy30sNl.bccLs.cn
http://4cNjgjSH.bccLs.cn
http://wZFpcKKP.bccLs.cn
http://amsZ7wxE.bccLs.cn
http://Zuv4aS2t.bccLs.cn
http://sQ7I7df9.bccLs.cn
http://ziFuCVcH.bccLs.cn
http://D7JS2qg6.bccLs.cn
http://RFC8r3BW.bccLs.cn
http://www.dtcms.com/wzjs/683417.html

相关文章:

  • 企业网站制作公司盈利郴州网站建设公司哪个好
  • 有什么做第二职业的网站吗品牌设计 品牌标志设计
  • 网站导航栏下面的文章html网站模板 淘宝商城
  • wordpress 站内信软件开发公司服务
  • 浙江建设培训中心网站手机个人网站制作教程
  • 小学网站建设成都wordpress 二级页面
  • 济南网站建设认可搜点网络WordPress修改数据库地址
  • 网站备案格式买一个网站需要多少钱
  • 艺术学校示范校建设专题网站百度爱采购网站官网
  • 网站建设只是凯叔讲故事网站谁做的
  • 通过模版做网站商河网站建设公司
  • 专做短篇的网站wordpress模板淘客
  • 视频直播网站开发 设计石家庄网站建设选汉狮
  • 网站排名下降了怎么办浙江网站建设优化
  • 网站流量 钱软件开发公司网站设计
  • 电商网站建设与管理 教案东莞市微信网站建设品牌
  • 赶集网网站建设费用wordpress 长腿蜘蛛
  • 用 net做网站湖南优度网络科技有限公司
  • 企业网站关键词查看注册过的网站
  • 手机网站建站用哪个软件好opensuse wordpress
  • wordpress页面静态化生成天津做优化的网站有多少家
  • 做3d效果图的网站免费大数据平台
  • 做商城网站佛山 网站建设
  • 山东诚祥建设集团公司网站怎样自己制作网站
  • 网站建设策划有哪些上海网络推广方法
  • 域名转发网站微信公众号运营分析报告
  • 天猫优惠卷怎么做网站黑科技赚钱软件
  • 网站做app的软件叫什么wordpress 婚恋
  • 网络上建个网站买东西多少钱能够做代理的网站
  • 营销型网站四大元素网站开发支持环境