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

一个网站怎么推广一个空间放多个网站

一个网站怎么推广,一个空间放多个网站,有关天猫网站开发的论文,如何进入网页编辑一、MyBatis动态 sql 是什么 动态 SQL 是 MyBatis 的强大特性之一。在 JDBC 或其它类似的框架中#xff0c;开发人员通常需要手动拼接 SQL 语句。根据不同的条件拼接 SQL 语句是一件极其痛苦的工作。例如#xff0c;拼接时要确保添加了必要的空格#xff0c;还要注意去掉列…一、MyBatis动态 sql 是什么 动态 SQL 是 MyBatis 的强大特性之一。在 JDBC 或其它类似的框架中开发人员通常需要手动拼接 SQL 语句。根据不同的条件拼接 SQL 语句是一件极其痛苦的工作。例如拼接时要确保添加了必要的空格还要注意去掉列表最后一个列名的逗号。而动态 SQL 恰好解决了这一问题可以根据场景动态的构建查询。 动态SQLcode that is executed dynamically它一般是根据用户输入或外部条件动态组合的SQL语句块。动态SQL能灵活的发挥SQL强大的功能、方便的解决一些其它方法难以解决的问题。相信使用过动态SQL的人都能体会到它带来的便利然而动态SQL有时候在执行性能 (效率)上面不如静态SQL而且使用不恰当往往会在安全方面存在隐患 (SQL 注入式攻击)。 1.Mybatis 动态 sql 是做什么的? Mybatis 动态 sql 可以让我们在 Xml 映射文件内以标签的形式编写动态 sql完成逻辑判断和动态拼接 sql 的功能。 2.Mybatis 的 9 种 动 态 sql 标 签有哪些 3.动态 sql 的执行原理 原理为使用 OGNL 从 sql 参数对象中计算表达式的值根据表达式的值动态拼接 sql以此来完成动态 sql 的功能。 二、MyBatis标签 1.if标签条件判断 MyBatis if 类似于 Java 中的 if 语句是 MyBatis 中最常用的判断语句。使用 if 标签可以节省许多拼接 SQL 的工作把精力集中在 XML 的维护上。 1不使用动态sql select idselectUserByUsernameAndSexresultTypeuser parameterTypecom.ys.po.User!-- 这里和普通的sql 查询语句差不多对于只有一个参数后面的 #{id}表示占位符里面          不一定要写id,写啥都可以但是不要空着如果有多个参数则必须写pojo类里面的属性 --select * from user where username#{username} and sex#{sex} /selectif 语句使用方法简单常常与 test 属性联合使用。语法如下: if test判断条件    SQL语句/if2使用动态sql 上面的查询语句我们可以发现如果 #{username} 为空那么查询结果也是空如何解决这个问题呢使用 if 来判断可多个 if 语句同时使用。 以下语句表示为可以按照网站名称name或者网址url进行模糊查询。如果您不输入名称或网址则返回所有的网站记录。但是如果你传递了任意一个参数它就会返回与给定参数相匹配的记录。 select idselectAllWebsite resultMapmyResult  select id,name,url from website where 11    if testname ! null        AND name like #{name}   /if    if testurl! null        AND url like #{url}    /if /select2.whereif标签 where、if同时使用可以进行查询、模糊查询 注意if失败后 where 关键字只会去掉库表字段赋值前面的and不会去掉语句后面的and关键字即注意where 只会去掉if 语句中的最开始的and关键字。所以下面的形式是不可取的 select idfindQuery resultTypeStudentinclude refidselectvp/whereif testsacc ! nullsacc like concat(% #{sacc} %)/ifif testsname ! nullAND sname like concat(% #{sname} %)/ifif testsex ! nullAND sex#{sex}/ifif testphone ! nullAND phone#{phone}/if/where /select这个“where”标签会知道如果它包含的标签中有返回值的话它就插入一个‘where’。此外如果标签返回的内容是以AND 或OR 开头的则它会剔除掉。 3.set标签 set可以用来修改 update idupdupdate studentsetif testsname ! nullsname#{sname},/ifif testspwd ! nullspwd#{spwd},/ifif testsex ! nullsex#{sex},/ifif testphone ! nullphone#{phone}/ifsid#{sid}/setwhere sid#{sid} /update4.choose(when,otherwise) 语句 有时候我们不想用到所有的查询条件只想选择其中的一个查询条件有一个满足即可使用 choose 标签可以解决此类问题类似于 Java 的 switch 语句 select idselectUserByChoose resultTypecom.ys.po.User parameterTypecom.ys.po.Userselect * from userwherechoosewhen testid ! and id ! nullid#{id}/whenwhen testusername ! and username ! nulland username#{username}/whenotherwiseand sex#{sex}/otherwise/choose/where/select也就是说这里我们有三个条件id、username、sex只能选择一个作为查询条件 如果 id 不为空那么查询语句为select * from user where id? 如果 id 为空那么看username 是否为空如果不为空那么语句为 select * from user where username?; 如果 username 为空那么查询语句为 select * from user where sex? 5.trim trim标记是一个格式化的标记可以完成set或者是where标记的功能 ①、用 trim 改写上面第二点的 ifwhere 语句 select idselectUserByUsernameAndSex resultTypeuser parameterTypecom.ys.po.Userselect * from user!-- whereif testusername ! nullusername#{username}/ifif testusername ! nulland sex#{sex}/if/where  --trim prefixwhere prefixOverridesand | orif testusername ! nulland username#{username}/ifif testsex ! nulland sex#{sex}/if/trim /selectprefix前缀 prefixoverride去掉第一个and或者是or ②、用 trim 改写上面第三点的 ifset 语句 !-- 根据 id 更新 user 表的数据 -- update idupdateUserById parameterTypecom.ys.po.Userupdate user u!-- setif testusername ! null and username ! u.username  #{username},/ifif testsex ! null and sex ! u.sex  #{sex}/if/set --trim prefixset suffixOverrides,if testusername ! null and username ! u.username  #{username},/ifif testsex ! null and sex ! u.sex  #{sex},/if/trimwhere id#{id} /updatesuffix后缀 suffixoverride去掉最后一个逗号也可以是其他的标记就像是上面前缀中的and一样 ③、trimif同时使用可以添加 insert idaddinsert  into studenttrim prefix( suffix) suffixOverrides,if testsname ! nullsname,/ifif testspwd ! nullspwd,/ifif testsex ! nullsex,/ifif testphone ! nullphone,/if/trimtrim prefixvalues ( suffix)  suffixOverrides,if testsname ! null#{sname},/ifif testspwd ! null#{spwd},/ifif testsex ! null#{sex},/ifif testphone ! null#{phone}/if/trim/insert6.MyBatis foreach标签 foreach是用来对集合的遍历这个和Java中的功能很类似。通常处理SQL中的in语句。 foreach 元素的功能非常强大它允许你指定一个集合声明可以在元素体内使用的集合项item和索引index变量。它也允许你指定开头与结尾的字符串以及集合项迭代之间的分隔符。这个元素也不会错误地添加多余的分隔符 你可以将任何可迭代对象如 List、Set 等、Map 对象或者数组对象作为集合参数传递给 foreach。当使用可迭代对象或者数组时index 是当前迭代的序号item 的值是本次迭代获取到的元素。当使用 Map 对象或者 Map.Entry 对象的集合时index 是键item 是值。 //批量查询 select idfindAll resultTypeStudent parameterTypeIntegerinclude refidselectvp/ WHERE sid inforeach itemids collectionarray  open( separator, close)#{ids}/foreach /select //批量删除 delete iddel  parameterTypeIntegerdelete  from  student  where  sid inforeach itemids collectionarray  open( separator, close)#{ids}/foreach /delete整合案例 xml ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.yzx.mapper.StuMappersql idselectvpselect  *  from  student/sqlselect idfind resultTypeStudentinclude refidselectvp//selectselect idfindbyid  resultTypestudentinclude refidselectvp/WHERE 11if testsid ! nullAND sid like #{sid}/if/selectselect idfindQuery resultTypeStudentinclude refidselectvp/whereif testsacc ! nullsacc like concat(% #{sacc} %)/ifif testsname ! nullAND sname like concat(% #{sname} %)/ifif testsex ! nullAND sex#{sex}/ifif testphone ! nullAND phone#{phone}/if/where/selectupdate idupdupdate studentsetif testsname ! nullsname#{sname},/ifif testspwd ! nullspwd#{spwd},/ifif testsex ! nullsex#{sex},/ifif testphone ! nullphone#{phone}/ifsid#{sid}/setwhere sid#{sid}/updateinsert idaddinsert  into studenttrim prefix( suffix) suffixOverrides,if testsname ! nullsname,/ifif testspwd ! nullspwd,/ifif testsex ! nullsex,/ifif testphone ! nullphone,/if/trimtrim prefixvalues ( suffix)  suffixOverrides,if testsname ! null#{sname},/ifif testspwd ! null#{spwd},/ifif testsex ! null#{sex},/ifif testphone ! null#{phone}/if/trim/insertselect idfindAll resultTypeStudent parameterTypeIntegerinclude refidselectvp/ WHERE sid inforeach itemids collectionarray  open( separator, close)#{ids}/foreach/selectdelete iddel  parameterTypeIntegerdelete  from  student  where  sid inforeach itemids collectionarray  open( separator, close)#{ids}/foreach/delete/mapper测试类: package com.yzx.test;import com.yzx.entity.Student; import com.yzx.mapper.StuMapper; 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 org.junit.After; import org.junit.Before; import org.junit.Test;import java.io.IOException; import java.io.InputStream; import java.util.List;public class StuTest {SqlSession sqlSessionnull;InputStream isnull;Beforepublic   void  before() throws IOException {//1.读取核心配置文件is Resources.getResourceAsStream(sqlMapperConfig.xml);//2.拿到工厂构建类SqlSessionFactoryBuilder sqlSessionFactoryBuildernew SqlSessionFactoryBuilder();//3.拿到具体工厂SqlSessionFactory buildsqlSessionFactoryBuilder.build(is);//4.拿到sessionsqlSession  build.openSession();}Afterpublic  void  after(){//7提交事务sqlSession.commit();//8.关闭资源sqlSession.close();if(is!null){try {is.close();} catch (IOException e) {e.printStackTrace();}};}//查询所有Testpublic  void  find(){//5.获取具体的mapper接口StuMapper mappersqlSession.getMapper(StuMapper.class);//6.调用执行ListStudent listmapper.find();list.forEach(a- System.out.println(a));}//查询单个Testpublic  void  findbyid(){StuMapper mappersqlSession.getMapper(StuMapper.class);ListStudent listmapper.findbyid(2);list.forEach(a- System.out.println(a));}//模糊查询Testpublic  void  findQuery(){StuMapper mappersqlSession.getMapper(StuMapper.class);Student  stunew Student();stu.setSname(小);stu.setSex(男);ListStudent listmapper.findQuery(stu);list.forEach(a- System.out.println(a));}//修改Testpublic  void  upd(){StuMapper mappersqlSession.getMapper(StuMapper.class);Student  stunew Student();stu.setSid(3);stu.setSname(小若);stu.setSex(人妖);int imapper.upd(stu);System.out.println(修改了i条数据  stu.toString());}//添加Testpublic  void  add(){StuMapper mappersqlSession.getMapper(StuMapper.class);Student  stunew Student();stu.setSname(小贺);stu.setSex(男);stu.setPhone(99999999);int imapper.add(stu);System.out.println(添加了i条数据  stu.toString());}//批量操作Testpublic  void  findAll(){StuMapper mappersqlSession.getMapper(StuMapper.class);Integer[] i{1,2,3,4};ListStudent listmapper.findAll(i);list.forEach(a- System.out.println(a));}//批量操作//批量删除Testpublic  void  del(){StuMapper mappersqlSession.getMapper(StuMapper.class);Integer[] i{1,2,3,4};int i1mapper.del(i);System.out.println(删除了i1条数据);} }7.sql 在实际开发中会遇到许多相同的SQL比如根据某个条件筛选这个筛选很多地方都能用到我们可以将其抽取出来成为一个公用的部分这样修改也方便一旦出现了错误只需要改这一处便能处处生效了此时就用到了sql这个标签了。 当多种类型的查询语句的查询字段或者查询条件相同时可以将其定义为常量方便调用。为求select结构清晰也可将 sql 语句分解。 sql idselectvpselect  *  from  student /sql8.include 这个标签和sql是天仙配是共生的include用于引用sql标签定义的常量。比如引用上面sql标签定义的常量 refid这个属性就是指定sql标签中的id值唯一标识 select idfindbyid  resultTypestudentinclude refidselectvp/WHERE 11if testsid ! nullAND sid like #{sid}/if /select9.如何引用其他XML中的SQL片段 比如你在com.xxx.dao.xxMapper这个Mapper的XML中定义了一个SQL片段如下 sql idBase_Column_List ID,MAJOR,BIRTHDAY,AGE,NAME,HOBBY/sql此时我在com.xxx.dao.PatinetMapper中的XML文件中需要引用如下 include refidcom.xxx.dao.xxMapper.Base_Column_List/include三、MyBatis关联查询 1.MyBatis一对多关联查询 !--一对多-- resultMap idmyStudent1 typestudent1id propertysid columnsid/result propertysname columnsname/result propertysex columnsex/result propertysage columnsage/collection propertylist ofTypeteacherid propertytid columntid/result propertytname columntname/result propertytage columntage//collection /resultMap!--一对多-- select idfind1 resultMapmyStudent1select  *  from  student1  s  left  join  teacher  t  on s.sidt.sid /select2.MyBatis多对一关联查询 !--多对一-- resultMap idmyTeacher typeteacherid propertytid columntid/result propertytname columntname/result propertytage columntage/association propertystudent1 javaTypeStudent1id propertysid columnsid/result propertysname columnsname/result propertysex columnsex/result propertysage columnsage//association /resultMap!--多对一-- select idfind2 resultMapmyTeacher select  *  from  teacher  t right join student1 s on  t.sids.sid /select3.MyBatis多对多关联查询 !--多对多 以谁为主表查询的时候主表约等于1的一方,另一方相当于多的一方-- select idfind3 resultMapmyStudent1select  *  from  student1 s  left join relevance r on  s.sidr.sid  left join teacher t on  r.tidt.tid /select
文章转载自:
http://www.morning.xzjsb.cn.gov.cn.xzjsb.cn
http://www.morning.drbwh.cn.gov.cn.drbwh.cn
http://www.morning.dnpft.cn.gov.cn.dnpft.cn
http://www.morning.kltmt.cn.gov.cn.kltmt.cn
http://www.morning.rahllp.com.gov.cn.rahllp.com
http://www.morning.srxhd.cn.gov.cn.srxhd.cn
http://www.morning.nrchx.cn.gov.cn.nrchx.cn
http://www.morning.zrrgx.cn.gov.cn.zrrgx.cn
http://www.morning.mlycx.cn.gov.cn.mlycx.cn
http://www.morning.lfqtp.cn.gov.cn.lfqtp.cn
http://www.morning.nbybb.cn.gov.cn.nbybb.cn
http://www.morning.rfkyb.cn.gov.cn.rfkyb.cn
http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn
http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn
http://www.morning.znrgq.cn.gov.cn.znrgq.cn
http://www.morning.hchrb.cn.gov.cn.hchrb.cn
http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn
http://www.morning.rdqzl.cn.gov.cn.rdqzl.cn
http://www.morning.lpsjs.com.gov.cn.lpsjs.com
http://www.morning.tpdg.cn.gov.cn.tpdg.cn
http://www.morning.cknsx.cn.gov.cn.cknsx.cn
http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn
http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn
http://www.morning.jfbgn.cn.gov.cn.jfbgn.cn
http://www.morning.pgcmz.cn.gov.cn.pgcmz.cn
http://www.morning.qymqh.cn.gov.cn.qymqh.cn
http://www.morning.ljygq.cn.gov.cn.ljygq.cn
http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn
http://www.morning.nldsd.cn.gov.cn.nldsd.cn
http://www.morning.xfhms.cn.gov.cn.xfhms.cn
http://www.morning.pwghp.cn.gov.cn.pwghp.cn
http://www.morning.jfch.cn.gov.cn.jfch.cn
http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn
http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn
http://www.morning.bkwd.cn.gov.cn.bkwd.cn
http://www.morning.mwpcp.cn.gov.cn.mwpcp.cn
http://www.morning.snbrs.cn.gov.cn.snbrs.cn
http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn
http://www.morning.djmdk.cn.gov.cn.djmdk.cn
http://www.morning.rsnn.cn.gov.cn.rsnn.cn
http://www.morning.zcsyz.cn.gov.cn.zcsyz.cn
http://www.morning.jydky.cn.gov.cn.jydky.cn
http://www.morning.yslfn.cn.gov.cn.yslfn.cn
http://www.morning.ryzgp.cn.gov.cn.ryzgp.cn
http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn
http://www.morning.qcslh.cn.gov.cn.qcslh.cn
http://www.morning.nynlf.cn.gov.cn.nynlf.cn
http://www.morning.mtyhk.cn.gov.cn.mtyhk.cn
http://www.morning.hprmg.cn.gov.cn.hprmg.cn
http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn
http://www.morning.jyzxt.cn.gov.cn.jyzxt.cn
http://www.morning.khtyz.cn.gov.cn.khtyz.cn
http://www.morning.mbprq.cn.gov.cn.mbprq.cn
http://www.morning.bqmsm.cn.gov.cn.bqmsm.cn
http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn
http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn
http://www.morning.litao4.cn.gov.cn.litao4.cn
http://www.morning.trrrm.cn.gov.cn.trrrm.cn
http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn
http://www.morning.gwqkk.cn.gov.cn.gwqkk.cn
http://www.morning.tsynj.cn.gov.cn.tsynj.cn
http://www.morning.xqndf.cn.gov.cn.xqndf.cn
http://www.morning.plwfx.cn.gov.cn.plwfx.cn
http://www.morning.gwwtm.cn.gov.cn.gwwtm.cn
http://www.morning.chbcj.cn.gov.cn.chbcj.cn
http://www.morning.yyzgl.cn.gov.cn.yyzgl.cn
http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn
http://www.morning.heleyo.com.gov.cn.heleyo.com
http://www.morning.wjjsg.cn.gov.cn.wjjsg.cn
http://www.morning.sldrd.cn.gov.cn.sldrd.cn
http://www.morning.bnrff.cn.gov.cn.bnrff.cn
http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn
http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn
http://www.morning.pbxkk.cn.gov.cn.pbxkk.cn
http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn
http://www.morning.jyjqh.cn.gov.cn.jyjqh.cn
http://www.morning.gstg.cn.gov.cn.gstg.cn
http://www.morning.psdsk.cn.gov.cn.psdsk.cn
http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn
http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn
http://www.tj-hxxt.cn/news/273744.html

相关文章:

  • 做网站服务器多大的好汽车门店管理系统
  • 深圳网站建设有哪些公司个人工作室怎么注册营业执照
  • 厦门个人建网站移动互联网营销
  • 普法网站建设移动应用开发技术
  • 中企动力网站建设 长春佛山企业网站建设机构
  • 六年级上册如何做网站自助网站设计平台
  • 无锡网站怎么优化排名做货代用什么网站找客户
  • 各主流网站做景区宣传个人怎么做贷款网站
  • 网站cms在线识别鼓楼做网站
  • 建站快车是什么合肥网站搭建工作室
  • 怎么用asp做网站办公空间设计案例整套
  • 网站怎么做域名解析建设的比较好的档案馆网站
  • 怎样让网站做301处理软件开发工程师怎么考
  • 地方网站开发网站开发基础知识简述
  • 做网站密云如何查网站的外链
  • 淘宝联盟的网站管理怎么做网站建设都 包括哪些
  • 高德地图搜索不到国外学seo推广
  • 旅游景点网站建设如何建设社区网站
  • 视频网站app怎么做的东莞网站设
  • dede淘宝客网站网站搭建后台
  • 兑换网站建设北湖区网站建设哪个好
  • 制作网站费用明细wordpress后台账号密码
  • 怎让做淘宝网站wordpress按钮编辑器
  • 做商城网站需要备案什么域名福田网站建设设计公司哪家好
  • 腾讯云如何建设网站首页家乡网站建设策划案
  • 网站排名优化首页网站建设优化服务咨询
  • 医疗机构 网站备案wordpress 站内搜索 慢
  • 做印刷网站公司做文案策划有些网站可看
  • 如何给网站做301重定向河北邢台有几个区县
  • 做网站设计前景怎么样视频模板套用免费