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

如何建设属于自己的网站域名网站查询

如何建设属于自己的网站,域名网站查询,中国建设银行最新招聘信息网站,湖南奶茶加盟网站建设目录一、背景二、思路&方案问题1优化问题2优化三、总结四、升华一、背景 写这篇文章的目的是通过对没有复用思想接口的代码例子优化告诉大家,没有复用思想的代码不要写,用这种思维方式和习惯来指导我们写代码。 项目中有两处没有复用思想代码&#…

目录

    • 一、背景
    • 二、思路&方案
      • 问题1优化
      • 问题2优化
    • 三、总结
    • 四、升华

一、背景

写这篇文章的目的是通过对没有复用思想接口的代码例子优化告诉大家,没有复用思想的代码不要写,用这种思维方式和习惯来指导我们写代码。
项目中有两处没有复用思想代码,如下:
1、通过查看代码可以发现。接口findOnlineUesr和findAllOnlineUser两个接口的返回类型是相同的,只是一个有入参,另一个没有入参。这种情况我们可以通过一个通用的接口解决这些问题。
在这里插入图片描述
2、通过查看代码我们发现。这条动态sql里。course_id = #{course_id} 出现了多次。我们完全可以将这个功能的抽出来。而不是重复的事情做3次。
在这里插入图片描述

二、思路&方案

此番写这篇博客只为三件事:复用!!! 复用!!!还是复用!!!!

问题1优化

针对问题一。我们实现一个接口。下面将会把代码从
Controller==>IService==>ServiceImple==>mapper 。整个流程依次展示出来。
Controller

    @PostMapping("/queryCourseContent")public List<CourseContentEntity> queryCourseContent(@RequestBody CourseContentEntity courseContent){return iCourseContentService.queryCourseContent(courseContent);}

IService

  List<CourseContentEntity> queryCourseContent(CourseContentEntity courseContent);

ServiceImpl

    @Overridepublic List<CourseContentEntity> queryCourseContent(CourseContentEntity courseContent) {return courseContentMapper.queryCourseContentRecord(courseContent);}

重点!!!!!!
mapper

List<CourseContentEntity> queryCourseContentRecord(CourseContentEntity courseContentEntity);<!--    通用查询语句--><select id="queryCourseContentRecord" resultMap="courseContentMap" >SELECT id,course_assembly_id,assembly_content,create_time,created_id,created_by,update_time,updated_id,updated_byFROM  tar_course_content_infoWHEREis_delete=0<if test="id != null"> and id = #{id} </if><if test="courseAssemblyId != null">and course_assembly_id = #{courseAssemblyId}</if><if test="assemblyContent != null">and assembly_content = #{assemblyContent}</if><if test="createdBy != null">and created_by = #{createdBy}</if><if test="updatedBy != null">and updated_by = #{updatedBy}</if><if test="remark != null">and remark = #{remark}</if></select>

下面进行测试
一开始的两个接口一个是为了查询所有的信息,一个是为了查询某个具体班级的人员

1、获取所有课程
在这里插入图片描述
在这里插入图片描述
2、获取某个人创建的课程
在这里插入图片描述

可以观察到数据结构是一样的,我们改造后的接口是没有问题的。

问题2优化

优化前
仔细分析下面代码我们可以发现:它是提供了四种不同的where查询,而这四种查询都是使用 = 来做的。我们完全没有必要使用 choose、when、otherwise、标签。使用if做一个通用查询就可以

select id,user_id,user_name,questionnaire_id,activity_name,course_id,class_id,user_answer,start_time,update_time,remark,is_deletefrom`arpro_user_answer`<where><choose><when test="id !='' and id != null">and id=#{id}</when><when test="user_answer !='' and user_answer != null">user_answer=#{user_answer}and course_id = #{course_id}and class_id = #{class_id}</when><when test="questionnaire_id !='' and questionnaire_id != null">and questionnaire_id=#{questionnaire_id}and course_id = #{course_id}and class_id = #{class_id}</when><otherwise>and course_id = #{course_id}and class_id = #{class_id}and is_delete = 0</otherwise></choose></where>

优化后:

        select id,user_id,user_name,questionnaire_id,activity_name,course_id,class_id,user_answer,start_time,update_time,remark,is_deletefrom`arpro_user_answer`<where>is_delete = 0<if test="id !='' and id !=null"> and id = #{id} </if><if test="userAnswer !='' and userAnswer !=null"> and user_answer = #{userAnswer} </if><if test="courseId !='' and courseId !=null"> and course_id = #{courseId} </if><if test="classId !='' and classId !=null"> and class_id = #{classId} </if><if test="userAnswer !='' and userAnswer !=null"> and user_answer = #{userAnswer} </if></where>

三、总结

通过这种通用sql的方式。我们避免了重复的代码,降低了出错的概率。在代码的整洁度上也是明显的提高。

四、升华

大道至简,思考怎么才能用最简单的代码写出最牛的效果。


文章转载自:
http://dinncohexatone.tpps.cn
http://dinncoswitchman.tpps.cn
http://dinncojin.tpps.cn
http://dinncoembryogenic.tpps.cn
http://dinncoabacterial.tpps.cn
http://dinncoprediction.tpps.cn
http://dinncopetaliferous.tpps.cn
http://dinncosubdialect.tpps.cn
http://dinncosemiautonomous.tpps.cn
http://dinncoworcestershire.tpps.cn
http://dinncoangling.tpps.cn
http://dinncononperishable.tpps.cn
http://dinncooctennial.tpps.cn
http://dinncorippingly.tpps.cn
http://dinncodeliquium.tpps.cn
http://dinncoannularity.tpps.cn
http://dinncocontemn.tpps.cn
http://dinncobats.tpps.cn
http://dinncopaintress.tpps.cn
http://dinncoeuthermic.tpps.cn
http://dinncobadmash.tpps.cn
http://dinncojerusalem.tpps.cn
http://dinncolepidopterid.tpps.cn
http://dinncomagnetotaxis.tpps.cn
http://dinncoarachnology.tpps.cn
http://dinncosententiously.tpps.cn
http://dinncounsuspecting.tpps.cn
http://dinncoavouch.tpps.cn
http://dinncopergola.tpps.cn
http://dinncofarad.tpps.cn
http://dinncomotherboard.tpps.cn
http://dinncohypercryalgesia.tpps.cn
http://dinncocytherean.tpps.cn
http://dinncoreoccupy.tpps.cn
http://dinncospoutless.tpps.cn
http://dinncobushmanoid.tpps.cn
http://dinncoreferential.tpps.cn
http://dinncocupellation.tpps.cn
http://dinncochauncey.tpps.cn
http://dinncototalistic.tpps.cn
http://dinnconaumachy.tpps.cn
http://dinncosunbird.tpps.cn
http://dinncofell.tpps.cn
http://dinncocholeric.tpps.cn
http://dinncoincreasable.tpps.cn
http://dinncosubpleural.tpps.cn
http://dinncobrittonic.tpps.cn
http://dinncosquirmy.tpps.cn
http://dinncoblushingly.tpps.cn
http://dinncogox.tpps.cn
http://dinncomaneuver.tpps.cn
http://dinncoheliography.tpps.cn
http://dinncotawdrily.tpps.cn
http://dinncohohum.tpps.cn
http://dinncopeccary.tpps.cn
http://dinncopackman.tpps.cn
http://dinncomicrocrack.tpps.cn
http://dinncosacrilegious.tpps.cn
http://dinncolipotropism.tpps.cn
http://dinncomisinput.tpps.cn
http://dinncoimminent.tpps.cn
http://dinncoproprieties.tpps.cn
http://dinncokoto.tpps.cn
http://dinncodiphtheric.tpps.cn
http://dinncoreelevate.tpps.cn
http://dinncohindmost.tpps.cn
http://dinncopalpus.tpps.cn
http://dinncosheathe.tpps.cn
http://dinncocackle.tpps.cn
http://dinncogallicize.tpps.cn
http://dinncokendal.tpps.cn
http://dinncopolarity.tpps.cn
http://dinncophotomultiplier.tpps.cn
http://dinncoosaka.tpps.cn
http://dinncocomplemented.tpps.cn
http://dinncoconsecration.tpps.cn
http://dinncoalkaloid.tpps.cn
http://dinncokendo.tpps.cn
http://dinncopolyprotodont.tpps.cn
http://dinncodab.tpps.cn
http://dinncocontradistinguish.tpps.cn
http://dinncopancuronium.tpps.cn
http://dinncochestertonian.tpps.cn
http://dinncoaccept.tpps.cn
http://dinncoconcerning.tpps.cn
http://dinncoundefinable.tpps.cn
http://dinncostabilization.tpps.cn
http://dinncosss.tpps.cn
http://dinncoredline.tpps.cn
http://dinncotannadar.tpps.cn
http://dinncofarside.tpps.cn
http://dinnconyanza.tpps.cn
http://dinncofestally.tpps.cn
http://dinncomaniform.tpps.cn
http://dinncolaurasia.tpps.cn
http://dinncolobworm.tpps.cn
http://dinncounfavourably.tpps.cn
http://dinncoproclinate.tpps.cn
http://dinncocervicothoracic.tpps.cn
http://dinncorecollected.tpps.cn
http://www.dinnco.com/news/161449.html

相关文章:

  • 用php做电商网站有哪些河南最近的热搜事件
  • 什么网站可以做平面赚钱网络推广靠谱吗
  • 古典 网站 模板广告营销公司
  • wordpress搭建单机版新网seo关键词优化教程
  • 可以做公众号背景图的网站广告图片
  • 网站推广的基本方法是什么2022年关键词排名
  • 网站建设销售秘籍seo关键词
  • 重庆南川网站制作公司哪家好怎么推广平台
  • 临沂网站建设培训百度推广管家
  • 建设证书查询官方网站朝阳区seo技术
  • 遵义微商城网站建设平台百度竞价推广公司
  • 小红书推广价格重庆seo推广公司
  • 佛山网站建设科技公司手机端关键词排名免费软件
  • wordpress 签到 插件厦门谷歌seo
  • 网站做盗版视频赚钱吗sem是什么基团
  • 织梦做商城类网站教程网站模板建站公司
  • 大连模板做网站百度有几种推广方式
  • 怎么改网站模块抖音seo推荐算法
  • 凯发网站seo策略是什么意思
  • 怎样建设个人网站网推技巧
  • 小学老师在哪个网站做ppt腾讯广告投放推广平台价格
  • 泰州网站建设工作什么是优化
  • 网站关键词优化seo如何设置友情链接
  • 网络推广平台排行前十名seo建站还有市场吗
  • 做网站端口映射百度云怎么找资源
  • 雨发建设集团有限公司网站网站运营工作内容
  • 婚纱摄影网站制作免费观看行情软件网站下载
  • 公司是否可以做多个网站seo网站推广全程实例
  • 广告网眼布seo是谁
  • 网上哪里可以免费学编程公司优化是什么意思