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

唐山乾正建设工程材料检测公司网站手机企业wap网站

唐山乾正建设工程材料检测公司网站,手机企业wap网站,湖南关键词网络科技有限公司,礼品网站如何做目录一、背景二、思路方案问题1优化问题2优化三、总结四、升华一、背景 写这篇文章的目的是通过对没有复用思想接口的代码例子优化告诉大家#xff0c;没有复用思想的代码不要写#xff0c;用这种思维方式和习惯来指导我们写代码。 项目中有两处没有复用思想代码#… 目录一、背景二、思路方案问题1优化问题2优化三、总结四、升华一、背景 写这篇文章的目的是通过对没有复用思想接口的代码例子优化告诉大家没有复用思想的代码不要写用这种思维方式和习惯来指导我们写代码。 项目中有两处没有复用思想代码如下 1、通过查看代码可以发现。接口findOnlineUesr和findAllOnlineUser两个接口的返回类型是相同的只是一个有入参另一个没有入参。这种情况我们可以通过一个通用的接口解决这些问题。 2、通过查看代码我们发现。这条动态sql里。course_id #{course_id} 出现了多次。我们完全可以将这个功能的抽出来。而不是重复的事情做3次。 二、思路方案 此番写这篇博客只为三件事复用 复用还是复用 问题1优化 针对问题一。我们实现一个接口。下面将会把代码从 ControllerIServiceServiceImplemapper 。整个流程依次展示出来。 Controller PostMapping(/queryCourseContent)public ListCourseContentEntity queryCourseContent(RequestBody CourseContentEntity courseContent){return iCourseContentService.queryCourseContent(courseContent);}IService ListCourseContentEntity queryCourseContent(CourseContentEntity courseContent); ServiceImpl Overridepublic ListCourseContentEntity queryCourseContent(CourseContentEntity courseContent) {return courseContentMapper.queryCourseContentRecord(courseContent);} 重点 mapper ListCourseContentEntity queryCourseContentRecord(CourseContentEntity courseContentEntity);!-- 通用查询语句--select idqueryCourseContentRecord resultMapcourseContentMap SELECT id,course_assembly_id,assembly_content,create_time,created_id,created_by,update_time,updated_id,updated_byFROM tar_course_content_infoWHEREis_delete0if testid ! null and id #{id} /ifif testcourseAssemblyId ! nulland course_assembly_id #{courseAssemblyId}/ifif testassemblyContent ! nulland assembly_content #{assemblyContent}/ifif testcreatedBy ! nulland created_by #{createdBy}/ifif testupdatedBy ! nulland updated_by #{updatedBy}/ifif testremark ! nulland 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_deletefromarpro_user_answerwherechoosewhen testid ! and id ! nulland id#{id}/whenwhen testuser_answer ! and user_answer ! nulluser_answer#{user_answer}and course_id #{course_id}and class_id #{class_id}/whenwhen testquestionnaire_id ! and questionnaire_id ! nulland questionnaire_id#{questionnaire_id}and course_id #{course_id}and class_id #{class_id}/whenotherwiseand 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_deletefromarpro_user_answerwhereis_delete 0if testid ! and id !null and id #{id} /ifif testuserAnswer ! and userAnswer !null and user_answer #{userAnswer} /ifif testcourseId ! and courseId !null and course_id #{courseId} /ifif testclassId ! and classId !null and class_id #{classId} /ifif testuserAnswer ! and userAnswer !null and user_answer #{userAnswer} /if/where 三、总结 通过这种通用sql的方式。我们避免了重复的代码降低了出错的概率。在代码的整洁度上也是明显的提高。 四、升华 大道至简思考怎么才能用最简单的代码写出最牛的效果。
http://www.dnsts.com.cn/news/65517.html

相关文章:

  • 四川城乡建设部网站黄页网站推广服务
  • 大良网站公司家在平湖 家在深圳
  • 网站单页生成器深圳设计周
  • 网站托管费用多少网站图片上传不了怎么办
  • 大家做网站都会去哪找素材企业如何申请网站
  • 麻将网站怎么做的装修网站应该怎么做
  • 旅游网站建设方案书成都网站建设v芯ee8888e
  • 网站建设怎么进后台收录批量查询工具
  • 做明星ps黄图网站做热图的在线网站
  • 亿省心网站托管什么是网络营销?如何理解网络营销的内涵
  • 浙江东阳市网站建设公司昆山网站
  • 园林景观 网站建设深圳招聘信息最新招聘信息查询
  • PS做网站报价做家教的正规网站
  • 关于网站建设的案例分析本溪seo优化
  • 上传商品的网站wordpress删除重装
  • 爱站关键词挖掘中航网站建设
  • 简述企业网站推广的一般策略网络营销资格证网络营销证书
  • 哈尔滨网站建设哈尔滨如何制作网站机器人
  • 做外贸生意用哪个网站如何设计公司标志图案
  • 鹤壁企业网站建设鞍山网站制作人才招聘
  • 网站服务器放置地怎么填如何做网站截流
  • 网站备案对网站负责人的要求wordpress 主题 带筛选
  • 大气网站模板制作钓鱼网站教程源码
  • 有了域名后怎么建设网站做课展网站
  • 可以建设一个网站国外好的网站
  • 电子商务网站开发课程教案网站微场景代码
  • 英语培训东莞网站建设做投诉网站赚钱吗
  • 云服务器放网站快么临夏金属装饰网站建设
  • o2o网站平台怎么做公司图案设计
  • 个人网站模块门户网站报价单