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

如何申请一个网站 做视频直播app运营策划

如何申请一个网站 做视频直播,app运营策划,网站备案资料修改,网站生成手机端文章目录 1. 什么是动态sql2. 动态sql之if3. 动态sql之where4. 动态sql之foreach5. sql片段抽取 此篇的代码基于 【Spring集成MyBatis】MyBatis的Dao层实现#xff08;基于配置#xff0c;非注解开发#xff09;续写 1. 什么是动态sql MyBatis映射… 文章目录 1. 什么是动态sql2. 动态sql之if3. 动态sql之where4. 动态sql之foreach5. sql片段抽取 此篇的代码基于 【Spring集成MyBatis】MyBatis的Dao层实现基于配置非注解开发续写 1. 什么是动态sql MyBatis映射文件中的SQL都比较简单有时当业务逻辑复杂时SQL是动态变化的此时在前面学的简单SQL就无法满足需求了。 具体地说假如我的数据库中有id,username,password三个字段假如我想查询usernamexxx的所有用户信息时候查询语句是 select * from user where usernamexxx 当我想查询usernamexxx且passwordxxx的所有用户信息时查询语句是 select * from user where usernamexxx and passwordxxx 这两者的共通之处就是username和password其实都是User里面的的一个属性假如我的输入以User为条件而不是以string为条件让SQL语句自动去判断我要根据什么查询有username根据username查询有password根据password查询有username和password时根据二者共同查询 如果我写的是select * from user where id#{id} and username#{username} and password#{password}此时sql语句等效为图中红字部分 但是这不是我们理想的效果我们想的是当password时语句自动变为 select * from user where id#{id} and username#{username} 这时候就无法查询出结果如果我们想要查询出结果就需要使用动态sql去实现 2. 动态sql之if 如果有if语法我们就可以很好地拼接SQL语句假如id ! 0就写 id#{id}假如username就写username#{username}依此类推 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.dao.UserMapperselect idfindByCondition parameterTypeuser resultTypeuserselect * from user where 11if testid!0and id#{id}/ifif testusername!nulland username#{username}/ifif testpassword!passwordand password#{password}/if/select/mapperif标签里的test写的就是判断再次运行测试代码仍能够查询出结果 package com.example.demo.service;import com.example.demo.dao.UserMapper; import com.example.demo.domain.User; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException; import java.io.InputStream; import java.util.List;public class ServiceDemo {public static void main(String[] args) throws IOException {InputStream inputStream Resources.getResourceAsStream(sqlMapConfig.xml);SqlSessionFactory sqlSessionFactory new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession sqlSessionFactory.openSession();UserMapper userMapper sqlSession.getMapper(UserMapper.class);// 模拟条件userUser condition new User();condition.setId(0);condition.setUsername(aaa);ListUser userList userMapper.findByCondition(condition);System.out.println(userList);} }结果 3. 动态sql之where 上面为了保证在无条件的时候不报错、也能够查询我们还多写了一个where 11 为了使得代码更优雅即有需要写的where时写上where无需where时不写还可以修改如下 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.dao.UserMapperselect idfindByCondition parameterTypeuser resultTypeuserselect * from user where 11whereif testid!0and id#{id}/ifif testusername!nulland username#{username}/ifif testpassword!passwordand password#{password}/if/where/select/mapper4. 动态sql之foreach 假如我们想查询id1或者id2或者id3…的 select * from user where id1 or id2 or id3 select * from user where id in(1, 2, 3) 这时候我们可能就需要用到循环 在XML文件中 select idfindByIds parameterTypelist resultTypeuserselect * from userwhereforeach collectionlist openid in( close) itemid separator,#{id}/foreach/where /select其中foreach中的 collection指定遍历的类型如果是列表就写list如果是数组就写array open写的是开始的内容 close写的是结束的内容 item里边是循环中当前的元素 seperator写的是分隔符 在接口里需要添加上该方法 public ListUser findByIds(ListInteger ids);在测试类中 ListInteger ids new ArrayListInteger(); ids.add(0); ids.add(1); ListUser userList userMapper.findByIds(ids);这样结果为id0和id1的数据 5. sql片段抽取 Sql中可以将重复的sql提取出来使用时通过include引用即可最终达到Sql重用的目的 例如我们原本有以下文件 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.dao.UserMapperselect idfindByCondition parameterTypeuser resultTypeuserselect * from userwhereif testid!0and id#{id}/ifif testusername!nulland username#{username}/ifif testpassword!passwordand password#{password}/if/where/selectselect idfindByIds parameterTypelist resultTypeuserselect * from userwhereforeach collectionlist openid in( close) itemid separator,#{id}/foreach/where/select/mapper其中两个语句都包含select * from user 那么我们就使用以下语法抽取sql片段简化编写sql标签 sql idselectUserselect * from user/sql然后使用inclue标签进行引用refid中写对应sql片段的id include refidselectUser/include所以以上代码可改写为 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.dao.UserMappersql idselectUserselect * from user/sqlselect idfindByCondition parameterTypeuser resultTypeuserinclude refidselectUser/includewhereif testid!0and id#{id}/ifif testusername!nulland username#{username}/ifif testpassword!passwordand password#{password}/if/where/selectselect idfindByIds parameterTypelist resultTypeuserinclude refidselectUser/includewhereforeach collectionlist openid in( close) itemid separator,#{id}/foreach/where/select/mapper
http://www.huolong8.cn/news/236183/

相关文章:

  • 响水做网站需要多少钱网站备案那个省份
  • 做好网站买了空间域名Wordpress xml 格式
  • 网站建设怎样才能吸引顾客免费的推广软件下载
  • 常州市网站制作什么是网络营销的核心工作
  • 企业做响应式网站好吗做外单的网站
  • 做设计找图片的网站建设信用卡在网站挂失块吗
  • 实验楼编程网站营销型企业网站建设步骤
  • ImQQ网站是怎么做的wordpress添加分类到菜单
  • 做网站应该会什么软件宁波在线网
  • 建设一个视频网站需要多少钱网站是每年都要付费吗
  • 北京网站建设 fim做宽带销售网站
  • 国内可以做的国外兼职网站深圳网站优化搜索
  • html网站建设流程图小语种网站怎么设计
  • 换网站公司做企业网站的人才
  • 西安市招聘网最新招聘信息企业网站怎么做seo优化
  • 郑州地方网络推广网站python网站开发pdf
  • 青岛php网站建设免费刷seo
  • 网站安全检测工具wordpress demo iframe
  • 咸阳网站建设专业公司哪家好深圳找人做网站
  • php网站开发介绍建设网站服务器自营方式
  • 做网站推广需要花多少钱网站建设丶金手指下拉15
  • 怎样做外部网站推广公司网站建设网站优化网络推广
  • 电脑网站搜索如何做专业做私募网站
  • 江北区城乡建设部网站首页抖音代运营有效果吗
  • 做注册会计师网站常用的网站有多种类型
  • 公司企业网站建设需要哪些网站布局怎么设计
  • 做统计图的网站js做的网站
  • 门户网站综合型门户郑州经济技术开发区属于什么区
  • 开发网站如何赚钱中宁企业网络推广联系人
  • 网站建设2018需要什么网站开发可选择的方案有哪些