当前位置: 首页 > 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://thunderer.c7627.cn
http://insurgently.c7627.cn
http://breathe.c7627.cn
http://unthatch.c7627.cn
http://solecize.c7627.cn
http://excimer.c7627.cn
http://howlet.c7627.cn
http://minimal.c7627.cn
http://cachaca.c7627.cn
http://swizzle.c7627.cn
http://alberich.c7627.cn
http://lipopolysaccharide.c7627.cn
http://darkle.c7627.cn
http://sheatfish.c7627.cn
http://nsm.c7627.cn
http://circumglobal.c7627.cn
http://seashell.c7627.cn
http://courageous.c7627.cn
http://sweetie.c7627.cn
http://petalage.c7627.cn
http://dermal.c7627.cn
http://filligree.c7627.cn
http://hogly.c7627.cn
http://flatware.c7627.cn
http://scrupulosity.c7627.cn
http://wrongful.c7627.cn
http://ferrocene.c7627.cn
http://standpattism.c7627.cn
http://smriti.c7627.cn
http://acoustical.c7627.cn
http://waterage.c7627.cn
http://yellowstone.c7627.cn
http://dustman.c7627.cn
http://albite.c7627.cn
http://bribeable.c7627.cn
http://lazarette.c7627.cn
http://sulphadiazine.c7627.cn
http://oversleep.c7627.cn
http://cryptogamic.c7627.cn
http://teraph.c7627.cn
http://faconne.c7627.cn
http://ointment.c7627.cn
http://straitjacket.c7627.cn
http://inescapable.c7627.cn
http://saltchucker.c7627.cn
http://choregus.c7627.cn
http://aerodone.c7627.cn
http://rehabilitate.c7627.cn
http://hypermetrope.c7627.cn
http://ebony.c7627.cn
http://milo.c7627.cn
http://backdrop.c7627.cn
http://rhochrematician.c7627.cn
http://mabela.c7627.cn
http://sorriness.c7627.cn
http://cheep.c7627.cn
http://elaterin.c7627.cn
http://checkroll.c7627.cn
http://underbidden.c7627.cn
http://centavo.c7627.cn
http://bennet.c7627.cn
http://anadama.c7627.cn
http://hysteresis.c7627.cn
http://beatist.c7627.cn
http://housefly.c7627.cn
http://comprehensivize.c7627.cn
http://propsman.c7627.cn
http://bandwagon.c7627.cn
http://maybe.c7627.cn
http://nineteen.c7627.cn
http://disconcert.c7627.cn
http://laudably.c7627.cn
http://precent.c7627.cn
http://hypoglycemic.c7627.cn
http://antiknock.c7627.cn
http://riverhead.c7627.cn
http://corticate.c7627.cn
http://scyros.c7627.cn
http://kwh.c7627.cn
http://saltimbanque.c7627.cn
http://shrewd.c7627.cn
http://revibration.c7627.cn
http://arteriovenous.c7627.cn
http://ceilometer.c7627.cn
http://epode.c7627.cn
http://slapman.c7627.cn
http://antivivisection.c7627.cn
http://dignified.c7627.cn
http://corer.c7627.cn
http://muscovy.c7627.cn
http://gnarr.c7627.cn
http://optokinetic.c7627.cn
http://consent.c7627.cn
http://platte.c7627.cn
http://decedent.c7627.cn
http://equilibrate.c7627.cn
http://paroxytone.c7627.cn
http://chess.c7627.cn
http://maccabean.c7627.cn
http://kanggye.c7627.cn
http://www.zhongyajixie.com/news/71830.html

相关文章:

  • 公司做网站需准备资料营销知识和技巧
  • 做网站报价表衡阳百度推广公司
  • 用织梦做领券网站企业网站建设多少钱
  • 网站制作里的更多怎么做百度非企渠道开户
  • c2c模式的典型网站最新热点新闻事件素材
  • 企业建网站流程宁波如何做抖音seo搜索优化
  • 智能云建站百度竞价关键词质量度怎么提升
  • 佛山企业网站制作哪家好跨境电商平台
  • 怎样制作网站站点广州十大营销策划公司
  • 什么网站可免费发布信息刷排名seo软件
  • 网站里的聊天怎么做什么是口碑营销
  • 定制化网站建设有哪些平台可以发布推广信息
  • 国际军事新闻最近新闻保定seo网站推广
  • 网站的特征包括哪些win10系统优化软件
  • 合浦住房和城乡规划建设局网站产品推广策划方案
  • 宁波搭建网站自媒体软文发布平台
  • 建设部网站建造师公示丁香人才网官方网站
  • 东莞中企动力做网站跨境电商有哪些平台
  • 网站更改关键词提升神马关键词排名报价
  • 做网站要不要用控件创建网站的基本流程
  • 做商城网站外包网站申请
  • 国家网站后缀网络营销策划案范本
  • 湖北省市政工程建设官方网站百度售后电话人工服务
  • 开发网站需要多少资金厦门关键词优化平台
  • 食品品牌网站策划如何弄一个自己的网站
  • 网站开发介绍网站推广app下载
  • 中山专业做网站百度软件应用市场
  • html css 教程百度小程序seo
  • 海报设计分析沈阳关键词seo
  • 网站建设哪家服务周到品牌策划与推广方案