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

做网站如何接单子安康市代驾公司

做网站如何接单子,安康市代驾公司,佛山推广平台,建设网站的公司兴田德润在哪里目录 一、概念 二、一对一 1、配置generatorConfig.xml 2、Vo包的编写 3、xml的sql编写 4、编写对应接口及实现类 5、测试 三、一对多 1、Vo包类的编写 2、xml的sql编写 3、编写对应接口及实现类 4、测试 四、多对多 1、Vo类 2、xml的sql配置 3、接口及接口实现…目录 一、概念 二、一对一 1、配置generatorConfig.xml 2、Vo包的编写 3、xml的sql编写 4、编写对应接口及实现类 5、测试 三、一对多 1、Vo包类的编写 2、xml的sql编写 3、编写对应接口及实现类 4、测试 四、多对多 1、Vo类 2、xml的sql配置 3、接口及接口实现类 4、测试 一、概念 1、MyBatis中表之间的关系是如何映射的处理的 resultType使用多表查询我们经常会resultTypejava.utils.Map ,我们不推荐这样写但是这样写对自己比较有利。 好处resultType 是直接将查询结果映射到 Java 对象可以使用简单的类型如 int、String或复杂的自定义类型。它的好处是简单直观易于使用。 弊端对于复杂的关系映射resultType 可能会变得冗长并且无法处理一对多或多对多的关系映射。 resultMapresultMap 允许我们定义复杂的映射规则将结果集中的多个字段映射到一个对象中。 好处可以处理复杂的关系映射支持一对多或多对多的关系映射。我们可以在 resultMap 中定义映射规则指定字段与属性间的映射关系并通过嵌套 resultMap 处理表之间的关系。 弊端相对于 resultTyperesultMap 的配置较为繁琐。 二、一对一 1、配置generatorConfig.xml 在我们的配置文件里面配置我们需要的几个表自动生成所需文件 table schema tableNamet_hibernate_book domainObjectNameHBookenableCountByExamplefalse enableDeleteByExamplefalseenableSelectByExamplefalse enableUpdateByExamplefalse/tabletable schema tableNamet_hibernate_book_category domainObjectNameHBookCategoryenableCountByExamplefalse enableDeleteByExamplefalseenableSelectByExamplefalse enableUpdateByExamplefalse/tabletable schema tableNamet_hibernate_category domainObjectNameHCategoryenableCountByExamplefalse enableDeleteByExamplefalseenableSelectByExamplefalse enableUpdateByExamplefalse/tabletable schema tableNamet_hibernate_order domainObjectNameHOrderenableCountByExamplefalse enableDeleteByExamplefalseenableSelectByExamplefalse enableUpdateByExamplefalse/tabletable schema tableNamet_hibernate_order_item domainObjectNameHOrderItemenableCountByExamplefalse enableDeleteByExamplefalseenableSelectByExamplefalse enableUpdateByExamplefalse/table 然后生成我们想要的model和xml映射文件 2、Vo包的编写 当然我们要先建立这个包里面的类才能更好的下一步。 我们现在示例的是一对一的所以根据前面以此类推我们建立一个HOrderItemVo类 package com.liwen.vo;import com.liwen.model.HOrder; import com.liwen.model.HOrderItem;/*** 软件包名 com.liwen.vo* 用户 liwen* create 2023-08-26 下午4:37* 注释说明*/ public class HOrderItemVo extends HOrderItem {private HOrder hOrder;public HOrder gethOrder() {return hOrder;}public void sethOrder(HOrder hOrder) {this.hOrder hOrder;} } 3、xml的sql编写 在我们的里面添加一个sql的方法编写 resultMap idHOrderItemVoMap typecom.liwen.vo.HOrderItemVoresult columnorder_itemId propertyorderItemId/result columnproduct_id propertyproductId/result columnquantity propertyquantity/result columnoid propertyoid/!--association是一对一的关系--association propertyhOrder javaTypecom.liwen.model.HOrderresult columnorder_id propertyorderId/result columnorder_no propertyorderNo//association/resultMapselect idselectByHOrderId resultMapHOrderItemVoMap parameterTypejava.lang.Integerselect *from t_hibernate_order o,t_hibernate_order_item oiwhere o.order_id oi.oidand oi.order_item_id #{oiid}/select 4、编写对应接口及实现类 在上面我们已经写好了sql我们生成对应的接口及接口实现方法。 在我们生成的HOrderItemMapper 接口里面编写 package com.liwen.mapper;import com.liwen.model.HOrderItem; import com.liwen.vo.HOrderItemVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository;Repository public interface HOrderItemMapper {int deleteByPrimaryKey(Integer orderItemId);int insert(HOrderItem record);int insertSelective(HOrderItem record);HOrderItem selectByPrimaryKey(Integer orderItemId);int updateByPrimaryKeySelective(HOrderItem record);int updateByPrimaryKey(HOrderItem record);HOrderItemVo selectByHOrderId(Param(oiid) Integer oiid); } 创建一个biz的包里面编写一个HOrderItemBiz接口类并且编写接口方法 package com.liwen.biz;import com.liwen.vo.HOrderItemVo;/*** 软件包名 com.liwen.biz* 用户 liwen* create 2023-08-26 下午4:48* 注释说明*/ public interface HOrderItemBiz {HOrderItemVo selectByHOrderId(Integer oiid); } 在这个biz里面新建一个impl包里面创建一个HOrderItemBizImpl 接口实现类继承HOrderItemBiz package com.liwen.biz.impl;import com.liwen.biz.HOrderItemBiz; import com.liwen.mapper.HOrderItemMapper; import com.liwen.vo.HOrderItemVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-26 下午4:48* 注释说明*/ Service public class HOrderItemBizImpl implements HOrderItemBiz {Autowiredprivate HOrderItemMapper hOrderItemMapper;Overridepublic HOrderItemVo selectByHOrderId(Integer oiid) {return hOrderItemMapper.selectByHOrderId(oiid);} } 5、测试 package com.liwen.biz.impl;import com.liwen.biz.HOrderItemBiz; import com.liwen.vo.HOrderItemVo; 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;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-26 下午4:58* 注释说明*/ RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations {classpath:spring-context.xml}) public class HOrderItemBizImplTest {Autowiredprivate HOrderItemBiz hOrderItemBiz;Testpublic void selectByHOrderId() {HOrderItemVo hOrderItemVo hOrderItemBiz.selectByHOrderId(27);System.out.println(hOrderItemVo);} } 三、一对多 1、Vo包类的编写 因为我们是一对多的所以我们再编写vo类的时候里面是使用list集合 package com.liwen.vo;import com.liwen.model.HOrder; import com.liwen.model.HOrderItem;import java.util.ArrayList; import java.util.List;/*** 软件包名 com.liwen.vo* 用户 liwen* create 2023-08-26 下午3:55* 注释说明*/ public class HOrderVo extends HOrder {// 一个订单存在多个订单项private ListHOrderItem hOrderItems new ArrayList();public ListHOrderItem gethOrderItems() {return hOrderItems;}public void sethOrderItems(ListHOrderItem hOrderItems) {this.hOrderItems hOrderItems;} } 2、xml的sql编写 在原本的基础的sql上我们增加一个一对多的sql !-- resultTypecom.liwen.vo.HOrderVo 在多表的字段是无法使用的--!-- 我们要写一个resultMap映射--resultMap idHOrderVoMap typecom.liwen.vo.HOrderVo!-- 每个订单对应的属性column数据库属性名property实体类属性名 --result columnorder_id propertyorderId/result columnorder_no propertyorderNo/!-- 我们设置hOrderItems数组里面的属性 --!-- collection是一对多的关系 --collection propertyhOrderItems ofTypecom.liwen.model.HOrderItemresult columnorder_itemId propertyorderItemId/result columnproduct_id propertyproductId/result columnquantity propertyquantity/result columnoid propertyoid//collection/resultMapselect idbyOid resultMapHOrderVoMap parameterTypejava.lang.Integerselect *from t_hibernate_order o,t_hibernate_order_item oiwhere o.order_id oi.oidand o.order_id #{oid}/select 3、编写对应接口及实现类 根据sql生成的对应的HOrderMapper 类里面生成已经编写好的sql方法 package com.liwen.mapper;import com.liwen.model.HOrder; import com.liwen.vo.HOrderVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository;Repository public interface HOrderMapper {int deleteByPrimaryKey(Integer orderId);int insert(HOrder record);int insertSelective(HOrder record);HOrder selectByPrimaryKey(Integer orderId);int updateByPrimaryKeySelective(HOrder record);int updateByPrimaryKey(HOrder record);//HOrderVo byOid(Param(oid) Integer oid); } 在biz包里面新建一个接口HOrderBiz  package com.liwen.biz;import com.liwen.vo.HOrderVo;/*** 软件包名 com.liwen.biz* 用户 liwen* create 2023-08-26 下午4:15* 注释说明*/ public interface HOrderBiz {HOrderVo byOid(Integer oid); } 在biz包里面的impl里面新建一个Java类实现HOrderBiz 接口 package com.liwen.biz.impl;import com.liwen.biz.HOrderBiz; import com.liwen.mapper.HOrderMapper; import com.liwen.vo.HOrderVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-26 下午4:16* 注释说明*/ Service public class HOrderBizImpl implements HOrderBiz {Autowiredprivate HOrderMapper hOrderMapper;Overridepublic HOrderVo byOid(Integer oid) {return hOrderMapper.byOid(oid);} } 4、测试 package com.liwen.biz.impl;import com.liwen.biz.HOrderBiz; import com.liwen.vo.HOrderVo; import org.junit.After; import org.junit.Before; 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.*;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-26 下午4:22* 注释说明*/ RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations {classpath:spring-context.xml}) public class HOrderBizImplTest {Autowiredprivate HOrderBiz hOrderBiz;Testpublic void byOid() {HOrderVo hOrderVo hOrderBiz.byOid(7);System.out.println(hOrderVo);}} 四、多对多 1、Vo类 package com.liwen.vo;import com.liwen.model.HBook; import com.liwen.model.HCategory;import java.util.List;/*** 软件包名 com.liwen.vo* 用户 liwen* create 2023-08-27 下午10:29* 注释说明*/ public class HBookVo extends HBook {private ListHCategory hCategoryList;public ListHCategory gethCategoryList() {return hCategoryList;}public void sethCategoryList(ListHCategory hCategoryList) {this.hCategoryList hCategoryList;} } package com.liwen.vo;import com.liwen.model.HBook; import com.liwen.model.HCategory;import java.util.ArrayList; import java.util.List;/*** 软件包名 com.liwen.vo* 用户 liwen* create 2023-08-27 下午11:03* 注释说明*/ public class HCategoryVo extends HCategory {private ListHBook hBooks new ArrayList();public ListHBook gethBooks() {return hBooks;}public void sethBooks(ListHBook hBooks) {this.hBooks hBooks;} } 2、xml的sql配置 分别在不同的xml配置文件里面配置 resultMap idHBookVo typecom.liwen.vo.HBookVoresult columnbook_id propertybookId/result columnbook_name propertybookName/result columnprice propertyprice/collection propertyhCategoryList ofTypecom.liwen.model.HCategoryresult columncategory_id propertycategoryId/result columncategory_name propertycategoryName//collection/resultMap!-- 根据书籍id查询出书籍信息及所属类别--select idselectByBId resultMapHBookVo parameterTypejava.lang.Integerselect *from t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category cwhere b.book_id bc.bidand bc.cid c.category_idand b.book_id #{bid}/select resultMap idHCategoryVo typecom.liwen.vo.HCategoryVoresult columncategory_id propertycategoryId/result columncategory_name propertycategoryName/collection propertyhBooks ofTypecom.liwen.model.HBookresult columnbook_id propertybookId/result columnbook_name propertybookName/result columnprice propertyprice//collection/resultMapselect idselectByCId resultMapHCategoryVo parameterTypejava.lang.Integerselect *from t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category cwhere b.book_id bc.bidand bc.cid c.category_idand c.category_id #{cid}/select 3、接口及接口实现类 在生成的接口类里面编写对应的接口方法 package com.liwen.mapper;import com.liwen.model.HBook; import com.liwen.vo.HBookVo; import org.apache.ibatis.annotations.Param;public interface HBookMapper {int deleteByPrimaryKey(Integer bookId);int insert(HBook record);int insertSelective(HBook record);HBook selectByPrimaryKey(Integer bookId);int updateByPrimaryKeySelective(HBook record);int updateByPrimaryKey(HBook record);HBookVo selectByBId(Param(bid) Integer bid); } package com.liwen.mapper;import com.liwen.model.HCategory; import com.liwen.vo.HCategoryVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository;Repository public interface HCategoryMapper {int deleteByPrimaryKey(Integer categoryId);int insert(HCategory record);int insertSelective(HCategory record);HCategory selectByPrimaryKey(Integer categoryId);int updateByPrimaryKeySelective(HCategory record);int updateByPrimaryKey(HCategory record);HCategoryVo selectByCId(Param(cid) Integer cid); } 在biz包里面新建一个HBookBiz接口类 package com.liwen.biz;import com.liwen.vo.HBookVo;/*** 软件包名 com.liwen.biz* 用户 liwen* create 2023-08-27 下午10:50* 注释说明*/ public interface HBookBiz {HBookVo selectByBId(Integer bid); } package com.liwen.biz;import com.liwen.vo.HCategoryVo;public interface HCategoryBiz {HCategoryVo selectByCId(Integer cid); } 在Biz里面的impl包里面新 package com.liwen.biz.impl;import com.liwen.biz.HBookBiz; import com.liwen.mapper.HBookMapper; import com.liwen.vo.HBookVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-27 下午10:53* 注释说明*/ Service public class HBookBizImpl implements HBookBiz {Autowiredprivate HBookMapper hBookMapper;Overridepublic HBookVo selectByBId(Integer bid) {return hBookMapper.selectByBId(bid);} } 建HBookBizImpl 接口实现HBookBiz接口类 package com.liwen.biz.impl;import com.liwen.biz.HBookBiz; import com.liwen.mapper.HBookMapper; import com.liwen.vo.HBookVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-27 下午10:53* 注释说明*/ Service public class HBookBizImpl implements HBookBiz {Autowiredprivate HBookMapper hBookMapper;Overridepublic HBookVo selectByBId(Integer bid) {return hBookMapper.selectByBId(bid);} } package com.liwen.biz.impl;import com.liwen.biz.HCategoryBiz; import com.liwen.mapper.HCategoryMapper; import com.liwen.vo.HCategoryVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-27 下午11:12* 注释说明*/ Service public class HCategoryBizImpl implements HCategoryBiz {Autowiredprivate HCategoryMapper hCategoryMapper;Overridepublic HCategoryVo selectByCId(Integer cid) {return hCategoryMapper.selectByCId(cid);} } 4、测试 package com.liwen.biz.impl;import com.liwen.biz.HBookBiz; import com.liwen.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;import static org.junit.Assert.*;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-27 下午10:59* 注释说明*/ RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations {classpath:spring-context.xml}) public class HBookBizImplTest {Autowiredprivate HBookBiz hBookBiz;Testpublic void selectByBId() {HBookVo hBookVo this.hBookBiz.selectByBId(8);System.out.println(hBookVo);} } package com.liwen.biz.impl;import com.liwen.biz.HCategoryBiz; import com.liwen.vo.HCategoryVo; 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.*;/*** 软件包名 com.liwen.biz.impl* 用户 liwen* create 2023-08-27 下午11:14* 注释说明*/ RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations {classpath:spring-context.xml}) public class HCategoryBizImplTest {Autowiredprivate HCategoryBiz hCategoryBiz;Testpublic void selectByCId(){HCategoryVo hCategoryVo hCategoryBiz.selectByCId(8);System.out.println(hCategoryVo);hCategoryVo.gethBooks().forEach(System.out::println);}}
http://www.yutouwan.com/news/456029/

相关文章:

  • 电子商务企业网站建设实训报告前端开发是什么专业
  • 荆州公司网站建设网页传奇游戏黑屏怎么解决
  • 某一网站seo策划方案wordpress二级域名建站
  • 挣钱最快的游戏株洲市网站关键词优化公司
  • 查看网站服务器信息建网站需要怎样做
  • 手机网站备案南京网站设计建设公司电话
  • 网站制作公司昆明深圳建设工程交易服务网南山
  • 网站建设的知识产权归属做外贸网站服务器要选择哪里的
  • 微信小程序公司网站怎么制作网站的规划与建设案例分析
  • 老网站删除做新站会影响收录吗网站申请空间
  • 基于wordpress个人博客网站论文关于小说网站的一些建设流程
  • 门户网站通俗理解怎样把自己做的网站上传
  • 网站建设重点步骤旅游网站开发结束语
  • 番禺网站制作 优帮云福建最大的网络公司排名
  • 网站统计访客数量怎么做求个2022手机能看的
  • 网站开发安装win10家庭版中国装修公司排行榜
  • 商场网站建设网站建设公司如何约客户
  • 百度一下建设部网站盗版电影网站建设成本
  • 网站建设优化广告流量商城网站建设相关费用
  • 机械技术支持东莞网站建设唐山网站制作方案
  • 乐清品牌网站建设dw软件教程
  • 电子商务网站实例创建自己的网站有什么用
  • 国外字体设计网站网站收录没排名
  • 手机网站服务器wordpress 媒体库 群晖
  • 有哪些做农产品的网站朝阳市网站建设
  • 网站网站制作价格建站网站专业网站建设总结
  • 网站开发是指微信运营商电话
  • 百度网站的优化方案百度seo优化培训
  • 怎么在工商网站做实名认证宁波seo外包sem
  • 做网站用哪种代码比较好推广网站建设先进个人总结