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

企业网站空间备案吗武汉seo报价

企业网站空间备案吗,武汉seo报价,获得网站源文件,o2o网站开发相关技术目录: 1.什么是关联关系映射: 一对一和多对多的区别 2.mybaits中的一对一&一对多关联关系配置 配置generatoeConfig文件 插件自动生成 ​编辑 写sql语句 创建 Ordermapper类 编写接口类 ​编辑 编写接口实现类 编写测试类 测试结果 一对…

目录: 

1.什么是关联关系映射:

一对一和多对多的区别

2.mybaits中的一对一&一对多关联关系配置

配置generatoeConfig文件

插件自动生成

​编辑 

 写sql语句

创建 Ordermapper类

编写接口类

​编辑 编写接口实现类

编写测试类

 测试结果

一对一

​编辑 测试结果:

3.mybatis中的多对多的关联关系配置

创建 HBookVo 

编写Sql

定义HBookMapper 接口

编写HBookBiz 接口

HBookBizImpl 接口实现类

编写测试类

测试结果 


1.什么是关联关系映射:

MyBatis是一个Java持久化框架,它提供了一种将数据库表与Java对象之间的关联关系进行映射的方式。关联关系映射是指将数据库表中的列与Java对象中的属性进行对应,以实现数据的读取和写入。通过MyBatis的关联关系映射,可以方便地进行数据库操作,包括查询、插入、更新和删除等操作。

一对一和多对多的区别

一对一和多对多是数据库中常见的关联关系类型。

一对一关系是指两个实体之间存在唯一的对应关系。在数据库中,可以通过在两个表之间共享相同的主键或外键来建立一对一关系。例如,一个人只能有一个身份证号码,而一个身份证号码也只能对应一个人。

多对多关系是指两个实体之间存在多个对应关系。在数据库中,可以通过引入第三个关联表来实现多对多关系。例如,一个学生可以选择多门课程,而一门课程也可以被多个学生选择。

总结来说,一对一关系是一种唯一的对应关系,而多对多关系是一种多个对应关系。

2.mybaits中的一对一&一对多关联关系配置

配置generatoeConfig文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration><!-- 引入配置文件 --><properties resource="jdbc.properties"/><!--指定数据库jdbc驱动jar包的位置--><classPathEntry location="C:\\temp2\\mvn_repository\\mysql\\mysql-connector-java\\5.1.44\\mysql-connector-java-5.1.44.jar"/><!-- 一个数据库一个context --><context id="infoGuardian"><!-- 注释 --><commentGenerator><property name="suppressAllComments" value="true"/><!-- 是否取消注释 --><property name="suppressDate" value="true"/> <!-- 是否生成注释代时间戳 --></commentGenerator><!-- jdbc连接 --><jdbcConnection driverClass="${jdbc.driver}"connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}"/><!-- 类型转换 --><javaTypeResolver><!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --><property name="forceBigDecimals" value="false"/></javaTypeResolver><!-- 01 指定javaBean生成的位置 --><!-- targetPackage:指定生成的model生成所在的包名 --><!-- targetProject:指定在该项目下所在的路径  --><javaModelGenerator targetPackage="com.zking.model"targetProject="src/main/java"><!-- 是否允许子包,即targetPackage.schemaName.tableName --><property name="enableSubPackages" value="false"/><!-- 是否对model添加构造函数 --><property name="constructorBased" value="true"/><!-- 是否针对string类型的字段在set的时候进行trim调用 --><property name="trimStrings" value="false"/><!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 --><property name="immutable" value="false"/></javaModelGenerator><!-- 02 指定sql映射文件生成的位置 --><sqlMapGenerator targetPackage="com.zking.mapper"targetProject="src/main/java"><!-- 是否允许子包,即targetPackage.schemaName.tableName --><property name="enableSubPackages" value="false"/></sqlMapGenerator><!-- 03 生成XxxMapper接口 --><!-- type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 --><!-- type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 --><!-- type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 --><javaClientGenerator targetPackage="com.zking.mapper"targetProject="src/main/java" type="XMLMAPPER"><!-- 是否在当前路径下新加一层schema,false路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --><property name="enableSubPackages" value="false"/></javaClientGenerator><!-- 配置表信息 --><!-- schema即为数据库名 --><!-- tableName为对应的数据库表 --><!-- domainObjectName是要生成的实体类 --><!-- enable*ByExample是否生成 example类 --><!--<table schema="" tableName="t_book" domainObjectName="Book"--><!--enableCountByExample="false" enableDeleteByExample="false"--><!--enableSelectByExample="false" enableUpdateByExample="false">--><!--&lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;--><!--&lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;--><!--&lt;!&ndash; 指定列的java数据类型 &ndash;&gt;--><!--&lt;!&ndash; <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;--><!--</table>--><table schema="" tableName="t_hibernate_book" domainObjectName="HBook"enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"></table><table schema="" tableName="t_hibernate_book_category" domainObjectName="HBookCategory"enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"></table><table schema="" tableName="t_hibernate_category" domainObjectName="HCategory"enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"></table><table schema="" tableName="t_hibernate_order" domainObjectName="Order"enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"></table><table schema="" tableName="t_hibernate_order_item" domainObjectName="OrderItem"enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"></table></context>
</generatorConfiguration>

插件自动生成

 

 写sql语句

创建 Ordermapper类

package com.zking.mapper;import com.zking.model.Order;
import com.zking.vo.OrderVo;
import org.apache.ibatis.annotations.Param;public interface OrderMapper {int deleteByPrimaryKey(Integer orderId);int insert(Order record);int insertSelective(Order record);Order selectByPrimaryKey(Integer orderId);int updateByPrimaryKeySelective(Order record);int updateByPrimaryKey(Order record);OrderVo selectbyoid(@Param("oid") Integer oid);
}

编写接口类

 编写接口实现类

编写测试类

package com.zking.biz.impl;import com.zking.biz.OrderBiz;
import com.zking.biz.OrderItemBiz;
import com.zking.vo.OrderItemVo;
import com.zking.vo.OrderVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import static org.junit.Assert.*;/*** @author bing人* @site* @company xy集团* @create 2023-09-04 9:46*/
//自动加载上下文
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-context.xml"})
public class OrderBizImplTest {
@Autowired
private OrderBiz orderBiz;
@Autowired
private OrderItemBiz orderItemBiz;@Testpublic void selectbyoid() {//更便于维护OrderVo orderVo = orderBiz.selectbyoid(8);System.out.println(orderVo);orderVo.getOrderItems().forEach(System.out::println);}@Testpublic void selectByOrderItemId() {OrderItemVo orderItemVo= orderItemBiz.selectByOrderItemId(27);System.out.println(orderItemVo);
//        System.out.println(orderItemVo.getOrder());}
}

 测试结果

一对一

 测试结果:

3.mybatis中的多对多的关联关系配置

创建 HBookVo 


package com.zking.vo;import com.zking.model.BookCategory;
import com.zking.model.HBook;
import lombok.Data;import java.util.List;/*** @author xy集团* @site blog.csdn.net/Justw320* @create 2023-0904 11:03*/
@Data
public class HBookVo extends HBook {private List<BookCategory> bookc = new ArrayList<>();}

编写Sql

  <resultMap id="HBookVoMap" type="com.ycxw.vo.HBookVo" ><result column="book_id" property="bookId"></result><result column="book_name" property="bookName"></result><result column="price" property="price"></result><collection property="bookc" ofType="com.ycxw.model.Category"><result column="category_id" property="categoryId"></result><result column="category_name" property="categoryName"></result></collection></resultMap><!--根据书籍的id查询书籍的信息及所属属性--><select id="selectByBookId" resultMap="HBookVoMap" parameterType="java.lang.Integer">SELECT*FROMt_hibernate_book b,t_hibernate_category c,t_hibernate_book_category bcWHEREb.book_id = bc.bidAND c.category_id = bc.bcidAND b.book_id = #{bid}</select>

定义HBookMapper 接口

HBookVo selectByBookId(@Param("bid") Integer bid);

 

编写HBookBiz 接口

package com.zking.biz;import com.zking.vo.HBookVo;/*** @author xy集团* @site blog.csdn.net/Justw320* @create 2023-09-04 11:12*/
public interface HBookBiz {HBookVo selectByBookId(Integer bid);
}

HBookBizImpl 接口实现类

package com.ycxw.biz.impl;import com.ycxw.biz.HBookBiz;
import com.ycxw.mapper.HBookMapper;
import com.ycxw.vo.HBookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** @author xy集团* @site blog.csdn.net/Justw320* @create 2023-0904 11:18*/
@Service
public class HBookBizImpl implements HBookBiz {@Autowiredprivate HBookMapper hBookMapper;@Overridepublic HBookVo selectByBookId(Integer bid) {return hBookMapper.selectByBookId(bid);}
}

编写测试类

package com.zking.biz.impl;import com.zking.biz.HBookBiz;
import com.zking.vo.HBookVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;/*** @author xy集团* @site blog.csdn.net/Justw320* @create 2023-09-04 11:22*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml"})
public class OrderBizImplTest {@Autowiredprivate HBookBiz hBookBiz;@Testpublic void selectByBookId(){HBookVo hBookVo = hBookBiz.selectByBookId(66);System.out.println(hBookVo);System.out.println(hBookVo.getBookc());}
}

测试结果 

http://www.hkea.cn/news/84186/

相关文章:

  • wordpress可以做大吗搜索引擎优化的英语简称
  • 民治专业做网站公司中国企业500强排行榜
  • 潍坊 公司 网站seo点击排名器
  • 网站可以做赌博广告建站宝盒
  • 运城市做网站英文seo外链
  • 江宁网站建设如何建立网上销售平台
  • 淄博企业网站建设有限公司搜索引擎关键词竞价排名
  • 网站的优点企业专业搜索引擎优化
  • 哪里有软件开发培训机构无锡seo培训
  • 网站怎么做反链seo是什么品牌
  • 技术型网站做哪一种好软文范例大全100
  • 百度搜索什么关键词能搜到网站seo高效优化
  • 网站搭建分站需要多少钱互联网营销策划
  • 音乐网站的音乐怎么做seo先上排名后收费
  • 清河做网站报价seo实战培训王乃用
  • wordpress 回收站在哪个文件夹营销方式和手段
  • 垂直型电商网站如何做快速排名软件哪个好
  • 做产品推广有网站比较好的免费自助建站平台
  • 番禺网站建设公司排名百度推广页面投放
  • 沈阳做微网站百度收录刷排名
  • 网站建设与管理技术发展seo是什么意思如何实现
  • 手机游戏开发制作公司最新seo视频教程
  • 网站优化过度被k长春seo排名公司
  • wordpress移除谷歌字体seo网站推广与优化方案
  • 十大景观设计公司排名seo权重查询
  • 水友做的yyf网站十大免费引流平台
  • 东莞公司网站制作百度识图网页版 在线
  • 企业级网站内容管理解决方案网站关键词快速排名服务
  • 影视采集网站怎么做收录关键词是网站seo的核心工作
  • 开发一个网站需要多少时间百度账号免费注册