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

外贸出口建站网站上的广告怎么做

外贸出口建站,网站上的广告怎么做,安徽省建设工程安全 协会网站,域名更新自动转跳前言 多表关联查询是软件开发中最常见的应用场景#xff0c;多表查询需要将数据实体之间的一对多、多对多、一对一的关系的转换为复杂的数据对象。mybaits提供的association和collection元素#xff0c;通过映射文件构造复杂实体对象#xff0c;在构造实体过程中#xff0…前言 多表关联查询是软件开发中最常见的应用场景多表查询需要将数据实体之间的一对多、多对多、一对一的关系的转换为复杂的数据对象。mybaits提供的association和collection元素通过映射文件构造复杂实体对象在构造实体过程中mybaits提供的了嵌套查询和嵌套结果查询两种查询方式前者通过执行多次SQL语句并支持延迟加载后者执行一次SQL语句通过SQL语句的执行结果构造实体。 实验目的 掌握嵌套查询的使用 掌握嵌套结果查询的使用 掌握单个实体association和实体集合collection的使用 实验内容 以教师和课程呈现的一对一关系为例验证association元素的使用 以教师和课程呈现的一对一关系为例验证嵌套查询使用 以教师和课程呈现的一对一关系为例验证嵌套结果查询使用 以学生和课程呈现的一对多关系为例验证collection元素的使用 以学生和课程呈现的一对多关系为例验证嵌套查询使用 以学生和课程呈现的一对多关系为例验证嵌套结果查询使用 实验步骤 1. 实验准备 创建表和数据维护表结构如下 学生表(tb_student) 字段名称字段代码数据类型备注学号snointeger主键自增学生姓名snamevarchar(50)年龄sageinteger 教师表(tb_tearcher) 字段名称字段代码数据类型备注工号tnointeger主键自增教师姓名tnamevarchar(50)年龄tageinteger 课程表(tb_course) 字段名称字段代码数据类型备注课程号cnointeger主键自增课程名cnamevarchar(50)学分ccreditinteger 学生选课表tb_sc 字段名称字段代码数据类型备注课程号cnointeger主键自增课程名cnamevarchar(50)学分ccreditinteger 每个表增加不少于5条记录 使用maven创建控制台工程搭建myBatis的运行环境编写实体类文件 教师实体类代码如下 Data public class TeacherEntity { private Integer tno; private String tname; private Integer tage; } 课程实体文件如下所示 Data public class CourseEntity {private int cno;private String cname;private int ccredit;private TeacherEntity teacher; }学生实体类代码如下 Data public class StudentEntity {private Integer sno;private String sname;private Integer sage;private ListCourseEntity courses; }编写接口文件 教师接口文件 public interface TeacherDao {TeacherEntity getTeacherByCourse(Integer cno); }课程接口文件 public interface CourseDao {ListCourseEntity getAllCourse();ListCourseEntity getAllCourseByResult();ListCourseEntity getCourseByStudentId(Integer sno); }学生接口文件 public interface StudentDao {ListStudentEntity getAllStudent();ListStudentEntity getAllStudent2(); }查询课程信息并显示该课程的任课教师一门课只安排一个教师 展示一对一信息需要在映射文件中使用association元素 使用嵌套查询 课程映射文件CourseMapper.xml代码如下 mapper namespacecom.bjwl.dao8.CourseDao resultMap idCoursePojo typecom.bjwl.pojo8.CourseEntityid propertycno columncno/idresult propertycname columncname/resultresult propertyccredit columnccredit/resultassociation propertyteacher columncno fetchTypeeagerjavaTypecom.bjwl.pojo8.TeacherEntity selectcom.bjwl.dao8.TeacherDao.getTeacherByCourse/association/resultMapselect idgetAllCourse resultMapCoursePojo select * from tb_course/select /mapper代码中首先定义了一个resultMap 建立复杂对象的映射关系association代表在课程实体CourseEntity中有一个教师teacher的属性对应数据类型是教师的实体二者之间通过列cno关联数据的获取是通过com.bjwl.dao8.TeacherDao.getTeacherByCourse实现的。其次定义获取全部课程数据使用的方法getAllCourse。 定义教师的映射文件TeacherMapper.xml在映射文件中定义getTeacherByCourse对应的SQL代码如下 mapper namespacecom.bjwl.dao8.TeacherDao select idgetTeacherByCourse resultTypecom.bjwl.pojo8.TeacherEntityselect * from tb_teacher where cno #{cno}/select /mapper测试代码如下 public void test11Nest() throws IOException {SqlSession sqlSession BatisUtils.getSqlSessionFactory().openSession();CourseDao dao sqlSession.getMapper(CourseDao.class);ListCourseEntity courses dao.getAllCourse();for (CourseEntity course : courses ){System.out.println(course.toString());}运行结果如下 上图中总共执行4次SQL语句。 使用嵌套结果查询 嵌套结果查询只执行一次SQL语句有查询结果中组织复杂实体对象映射文件代码如下 mapper namespacecom.bjwl.dao8.CourseDao resultMap idCoursePojo2 typecom.bjwl.pojo8.CourseEntity id propertycno columncno/id result propertycname columncname/result result propertyccredit columnccredit/result association propertyteacher javaTypecom.bjwl.pojo8.TeacherEntity id propertytno columntno/id result propertytname columntname/result result propertytage columntage/result /association /resultMap select idgetAllCourseByResult resultMapCoursePojo2 select * from tb_course a left join tb_teacher b on a.cno b.cno /select /mapper 代码中association 定义返回结果集中列和实体属性的对应关系。测试代码如下图所示 public void test11Result() throws IOException { SqlSession sqlSession BatisUtils.getSqlSessionFactory().openSession(); CourseDao dao sqlSession.getMapper(CourseDao.class); ListCourseEntity courses dao.getAllCourseByResult(); for (CourseEntity course : courses ){ System.out.println(course.toString()); } } 运行结果如下图所示 查询学生信息并显示该学生所修课程一个学生有多门课程 展示一对多信息需要在映射文件中使用实体集合collection元素 使用嵌套查询 学生映射文件StudentMapping代码如下 mapper namespacecom.bjwl.dao8.StudentDao resultMap idstudentInfo typecom.bjwl.pojo8.StudentEntityid propertysno columnsno/idresult propertysname columnsname/resultresult propertysage columnsage/resultcollection propertycourses columnsno ofTypecom.bjwl.pojo8.CourseEntityselectcom.bjwl.dao8.CourseDao.getCourseByStudentId/collection/resultMapselect idgetAllStudent resultMapstudentInfoselect * from tb_student/select /mapper代码中首先定义了一个resultMap 建立复杂对象的映射关系collection 代表在学生实体中StudentEntity中有一个课程courses的属性二者之间通过列sno关联数据的获取是通过com.bjwl.dao8.CourseDao.getCourseByStudentId实现的。其次定义获取全部课程数据使用的方法getCourseByStudentId。 定义课程的映射文件TeacherMapper.xml在映射文件中定义getCourseByStudentId对应的SQL代码如下 mapper namespacecom.bjwl.dao8.CourseDao select idgetCourseByStudentId resultTypecom.bjwl.pojo8.CourseEntityselect * from tb_course a,tb_sc bwhere a.cno b.cno andb.sno #{sno}/select /mapper测试代码如下 public void test1nNest() throws IOException {SqlSession sqlSession BatisUtils.getSqlSessionFactory().openSession(ExecutorType.BATCH);StudentDao dao sqlSession.getMapper(StudentDao.class);ListStudentEntity students dao.getAllStudent();for (StudentEntity student : students ){System.out.println(student.toString());}}执行结果如下图所示 使用嵌套结果 对应的映射文件为 mapper namespacecom.bjwl.dao8.StudentDao resultMap idstudentInfo2 typecom.bjwl.pojo8.StudentEntityid propertysno columnsno/idresult propertysname columnsname/resultresult propertysage columnsage/resultcollection propertycourses columnsno ofTypecom.bjwl.pojo8.CourseEntityid propertycno columncno/idresult propertycname columncname/resultresult propertyccredit columnccredit/result/collection/resultMapselect idgetAllStudent2 resultMapstudentInfo2SELECT aa.*,bb.* FROM(SELECT a.sno,a.sname,a.sage,b.cnoFROM tb_student a LEFT JOIN tb_sc b ON a.sno b.sno) aa LEFT JOIN tb_course bbON aa.cno bb.cno;/select测试代码如下 public void test1nResult() throws IOException {SqlSession sqlSession BatisUtils.getSqlSessionFactory().openSession(ExecutorType.BATCH);StudentDao dao sqlSession.getMapper(StudentDao.class);ListStudentEntity students dao.getAllStudent2();for (StudentEntity student : students ){System.out.println(student.toString());}}运行结果如下图所示 多对多的关系可以当作两个一对多的关系完成
http://wiki.neutronadmin.com/news/206197/

相关文章:

  • 企业怎样做网站开一个软件开发公司需要多少钱
  • 商丘做网站哪家好全网营销思路
  • 大气网站首页模板集团网站建设基础方案
  • 个人网站如果做c2g的代表性电商平台
  • 做招聘网站排名深圳景观设计公司排行
  • 建设网站公司排名领硕网站seo优化
  • 东莞网站营销佛山网站建设优势
  • 哈尔滨的网站建设公司职工之家网站开发新闻稿
  • 青岛移动网站开发网站内的地图导航怎么做的
  • 淄博乐达信息技术网站页面设计层级一般控制
  • 响应式手机网站建设简单制作网站的过程
  • 查网站怎么做的广州建网站哪儿济南兴田德润简介
  • wordpress 开启评论苏州网站排名优化
  • 建商城网站公司免费行情软件app网站不下载
  • 网站发展清流县建设局网站
  • 南京 网站建设免费做自己的网站
  • 网站文字列表页模板昆明公司网站制作
  • 行业 专业 网站建设宜宾做网站的公司
  • 深圳百度网站排名优化重庆中信建投期货有限公司
  • 专门做市场调查的网站合肥做兼职网站
  • 国通快速建站wordpress添加百度自动推送
  • 浅谈旅游网站的规划与建设建设银行网站转账必须u盾吗
  • 网站制作技术长沙百度租车有限公司
  • 广告手机网站制作织梦cms做电影网站
  • 网站开发一个页面多少钱寻模板网站源码
  • 阿里云上做网站有哪些可以做策划方案的网站
  • wordpress foote在哪里短视频seo推广隐迅推专业
  • iis网站怎么做域名绑定房地产基础知识
  • 网络规划设计师大纲网站建设好怎么优化
  • 北京seo网站优化公司2万一3万电动汽车