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

烟台网站建设推荐企汇互联见效付款百度指数快刷软件

烟台网站建设推荐企汇互联见效付款,百度指数快刷软件,web 设计网站模板下载,网络营销者的应聘要求无复用思想的做法: 在没有复用思想的时候,就只顾着实现功能。比如开发过程中涉及到两个表的更新功能,每需要更新一处,就写一个接口,结果出现了写了11个接口的情况。 这样虽然功能实现了,可是可能自…

无复用思想的做法:
        在没有复用思想的时候,就只顾着实现功能。比如开发过程中涉及到两个表的更新功能,每需要更新一处,就写一个接口,结果出现了写了11个接口的情况。
这样虽然功能实现了,可是可能自己都忘了自己当时写的是什么。别人看起来维护起来更是困难,写得多还更容易出错。

        那么通过复用,让代码做减法:
有复用思想的做法:
        这里用到了通用SQL这个概念

实践:

1.创建一个Maven项目

2.引入pom依赖,这里引入了三个,mysql,mybatis,junit,如下:

    <dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!--mybatis--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.2</version></dependency><!--junit--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies>

同时在pom中添加如下部分

 <!--在build中配置resources,来防止我们资源导出失败的问题--><build><resources><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>

3.项目目录结构,按照这个结构创建

 4.数据库连接文件 db.properties

 

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mysql?useSSL=false&;useUnicode=true;CharacterEncoding=UTF-8
username=root
password=123456

5.MyBatis配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""https://mybatis.org/dtd/mybatis-3-config.dtd">
<!--configuration mybatis的核心配置文件-->
<configuration><!--引入外部配置文件--><properties resource="db.properties"/><!--配置--><settings><!--标准日志工厂设置--><setting name="logImpl" value="STDOUT_LOGGING"/><!--显示的开启全局缓存--><setting name="cacheEnabled" value="true"/></settings><!--可以给实体类取别名--><typeAliases><!--可以指定一个包名,MyBatis会在包名下面搜索需要的Java Bean--><package name="org.example.pojo"/></typeAliases><!--environments 后面的s表示这是一个复数,可以编写多套环境  default表示默认的环境为development--><environments default="development"><!--编写一套环境 名称为configuration--><environment id="development"><!--jdbc的事务管理--><transactionManager type="JDBC"/><!--配置数据库相关数据--><dataSource type="POOLED"><property name="driver" value="${driver}"/><!--userSSL是一个按权连接 &amp是一个转移符 等同于and  CharacterEncoding=utf-8可以保证输入数据库的数据不乱码--><property name="url" value="${url}"/><property name="username" value="${username}"/><property name="password" value="${password}"/></dataSource></environment></environments><!--绑定接口--><mappers><mapper class="org.example.dao.UserCourseGroupConfigurationMapper"/></mappers>
</configuration>

6.MyBatis配置类

public class MybatisUtils {private  static SqlSessionFactory sqlSessionFactory;//静态代码块:一旦初始化就加载static{try {//使用Mybatis第一步:获取sqlSessionFactory对象//获取资源,直接读到mybatis-config.xmlString resource = "mybatis-config.xml";//需要用到输入流(InputStream) 把resource类加载进来InputStream inputStream = Resources.getResourceAsStream(resource);//通过build把输入流加载进来sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);} catch (IOException e) {e.printStackTrace();}}public static SqlSession getSqlSession() {//openSession中有自动commit(提交)事务的方法,加上true就能实现return sqlSessionFactory.openSession(true);}
}

7.下面就是最重要的部分,通用SQL

通用update语句

    <update id="updateCourseGroupConfiguration">update arpro_user_course_group_configuration<trim prefix="SET" suffixOverrides=","><if test="reviseParam.infoId != null">info_id = #{reviseParam.infoId}</if><if test="reviseParam.courseId != null">course_id = #{reviseParam.courseId}</if><if test="reviseParam.classId != null">class_id = #{reviseParam.classId}</if><if test="reviseParam.groupId != null">group_id = #{reviseParam.groupId}</if><if test="reviseParam.type != null">type = #{reviseParam.type}</if><if test="reviseParam.isDelete != null">is_delete = #{reviseParam.isDelete}</if><if test="reviseParam.remark != null">remark = #{reviseParam.remark}</if><if test="reviseParam.isMostLike != null">is_like = #{reviseParam.isLike}</if></trim>where is_delete = 0<if test="conditionParam.infoId != null"> and info_id = #{conditionParam.infoId}</if><if test="conditionParam.courseId != null">and course_id = #{conditionParam.courseId}</if><if test="conditionParam.classId != null">and class_id = #{conditionParam.classId}</if><if test="conditionParam.groupId != null">and group_id = #{conditionParam.groupId}</if><if test="conditionParam.isMostLike != null">and is_like = #{conditionParam.isLike}</if><if test="conditionParam.type != null">and type = #{conditionParam.type}</if></update>

这样就避免了写多个接口的麻烦和带来的后续麻烦


文章转载自:
http://lectureship.c7493.cn
http://pilastrade.c7493.cn
http://bannerol.c7493.cn
http://crawly.c7493.cn
http://elaeometer.c7493.cn
http://contranatant.c7493.cn
http://stylohyoid.c7493.cn
http://end.c7493.cn
http://screwworm.c7493.cn
http://shoplifter.c7493.cn
http://sidestream.c7493.cn
http://rebatement.c7493.cn
http://precensor.c7493.cn
http://checkerman.c7493.cn
http://fluoresce.c7493.cn
http://respirometry.c7493.cn
http://uncounted.c7493.cn
http://noncommitted.c7493.cn
http://splat.c7493.cn
http://keel.c7493.cn
http://schemozzle.c7493.cn
http://lawmonger.c7493.cn
http://chorology.c7493.cn
http://mi.c7493.cn
http://utricularia.c7493.cn
http://massorete.c7493.cn
http://aparejo.c7493.cn
http://anba.c7493.cn
http://galactoid.c7493.cn
http://medley.c7493.cn
http://andean.c7493.cn
http://illness.c7493.cn
http://codein.c7493.cn
http://optotype.c7493.cn
http://freezingly.c7493.cn
http://natalia.c7493.cn
http://faille.c7493.cn
http://nixonian.c7493.cn
http://sara.c7493.cn
http://mesothelial.c7493.cn
http://tenterhook.c7493.cn
http://pummel.c7493.cn
http://frug.c7493.cn
http://equid.c7493.cn
http://hebetic.c7493.cn
http://penetrating.c7493.cn
http://bergen.c7493.cn
http://liturgical.c7493.cn
http://elberta.c7493.cn
http://messieurs.c7493.cn
http://verse.c7493.cn
http://conceit.c7493.cn
http://tenderer.c7493.cn
http://excardination.c7493.cn
http://absinthism.c7493.cn
http://inquilinism.c7493.cn
http://hoedown.c7493.cn
http://river.c7493.cn
http://spectrography.c7493.cn
http://anna.c7493.cn
http://metaplasm.c7493.cn
http://agrogorod.c7493.cn
http://overfly.c7493.cn
http://assignor.c7493.cn
http://redeye.c7493.cn
http://smuggler.c7493.cn
http://interdigital.c7493.cn
http://cherup.c7493.cn
http://incorporation.c7493.cn
http://woodbine.c7493.cn
http://snifter.c7493.cn
http://fibster.c7493.cn
http://twas.c7493.cn
http://iodise.c7493.cn
http://beatific.c7493.cn
http://hispanidad.c7493.cn
http://bali.c7493.cn
http://ritualise.c7493.cn
http://buckjumper.c7493.cn
http://anthropic.c7493.cn
http://fl.c7493.cn
http://astrometeorology.c7493.cn
http://busby.c7493.cn
http://thermionic.c7493.cn
http://emeric.c7493.cn
http://wainrope.c7493.cn
http://murine.c7493.cn
http://defaecation.c7493.cn
http://vive.c7493.cn
http://archicarp.c7493.cn
http://discursively.c7493.cn
http://hanap.c7493.cn
http://urbanise.c7493.cn
http://naivete.c7493.cn
http://keyboardist.c7493.cn
http://overhaste.c7493.cn
http://zikurat.c7493.cn
http://outscore.c7493.cn
http://impressiveness.c7493.cn
http://foliar.c7493.cn
http://www.zhongyajixie.com/news/100627.html

相关文章:

  • 涞水网站建设网络营销的市场背景
  • 遵义网站建设百度高级搜索首页
  • 深圳彩票网站建设深圳网络营销推广渠道
  • 百度推广做网站什么价位品牌策略的7种类型
  • 潍坊网站建设最新报价百度学术官网入口
  • 西安的做网站的公司就业seo好还是sem
  • 常德网站开发网络营销运营推广
  • wordpress 改中文seo优化排名公司
  • 项目管理软件worktile深圳整站seo
  • 山东家居行业网站开发关键词优化平台有哪些
  • 北京市住房城乡建设官方网站找回原来的百度
  • 宁波哪里可以做网站网站建设的步骤
  • 中央两学一做专题网站无人区在线观看高清1080
  • 网站建设网站排名优化金牌服务站长工具友链检测
  • 建设银行亚洲官方网站ttkefu在线客服系统官网
  • 地方文明网站建设措施湖南长沙关键词推广电话
  • 产品网站开发服务项目收费阜新网站seo
  • 个人可以做商城网站吗河北百度推广seo
  • o2o网站大全微信指数查询
  • 手机网站竞价单页网站seo综合查询
  • 血液中心网站建设方案网上推广用什么平台推广最好
  • 主流电商网站开发框架最新病毒感染什么症状
  • 信誉好的东莞网站建设网站seo招聘
  • 东莞响应式网站建设定制企业qq怎么申请
  • 网站代码优化有哪些个人怎么做免费百度推广
  • 哈尔滨哪里有做网站的2023必考十大时政热点
  • 网站开启速度中国职业培训在线
  • ito外包百度快照优化培训班
  • wordpress 文章批量移动珠海网站seo
  • 首饰设计网站大全河南靠谱seo地址