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

团购网站大全做相册2021年中国关键词

团购网站大全做相册,2021年中国关键词,h5网站建设哪家好,做网站需要填什么动态 SQL 是 MyBatis 的强大特性之一。在 JDBC 或其它类似的框架中,开发人员通常需要手动拼接 SQL 语句。根据不同的条件拼接 SQL 语句是一件极其痛苦的工作。例如,拼接时要确保添加了必要的空格,还要注意去掉列表最后一个列名的逗号。而动态…

动态 SQL 是 MyBatis 的强大特性之一。在 JDBC 或其它类似的框架中,开发人员通常需要手动拼接 SQL 语句。根据不同的条件拼接 SQL 语句是一件极其痛苦的工作。例如,拼接时要确保添加了必要的空格,还要注意去掉列表最后一个列名的逗号。而动态 SQL 恰好解决了这一问题,可以根据场景动态的构建查询

动态 SQL 只有几个基本元素,与 JSTL 或 XML 文本处理器相似,十分简单明了,大量的判断都可以在 MyBatis 的映射 XML 文件里配置,以达到许多需要大量代码才能实现的功能。动态 SQL 大大减少了编写代码的工作量,更体现了 MyBatis 的灵活性、高度可配置性和可维护性

if标签:条件判断

MyBatis if 类似于 Java 中的 if 语句,是 MyBatis 中最常用的判断语句

if 语句使用方法简单,常常与 test 属性联合使用。语法如下

<if test="判断条件">SQL语句
</if>

当判断条件为 true 时,才会执行所包含的 SQL 语句。
最常见的场景是在 if 语句中包含 where 子句,例如

<select id="selectAllWebsite" resultMap="myResult">select id,name,url from website<if test="name != null">where name like #{name}</if>
</select>

以上代表表示根据网站名称去查找相应的网站信息,但是网站名称是一个可填可不填的条件,不填写的时候不作为查询条件。


可多个 if 语句同时使用。以下语句表示为可以按照网站名称(name)或者网址(url)进行模糊查询。如果您不输入名称或网址,则返回所有的网站记录。但是,如果你传递了任意一个参数,它就会返回与给定参数相匹配的记录。

<select id="selectAllWebsite" resultMap="myResult">select id,name,url from website where 1=1<if test="name != null">AND name like #{name}</if><if test="url!= null">AND url like #{url}</if>
</select>

choose、when和otherwise标签

MyBatis 中动态语句 choose-when-otherwise 类似于 Java 中的 switch-case-default 语句。由于 MyBatis 并没有为 if 提供对应的 else 标签,如果想要达到<if>...<else>...</else> </if> 的效果,可以借助 <choose>、<when>、<otherwise> 来实现。
动态语句 choose-when-otherwise 语法如下

<choose><when test="判断条件1">SQL语句1</when ><when test="判断条件2">SQL语句2</when ><when test="判断条件3">SQL语句3</when ><otherwise>SQL语句4</otherwise>
</choose>

choose 标签按顺序判断其内部 when 标签中的判断条件是否成立,如果有一个成立,则执行相应的 SQL 语句,choose 执行结束;如果都不成立,则执行 otherwise 中的 SQL 语句。这类似于 Java 的 switch 语句,choose 为 switch,when 为 case,otherwise 则为 default。

示例

以下示例要求:

  • 当网站名称不为空时,只用网站名称作为条件进行模糊查询;
  • 当网站名称为空,而网址不为空时,则用网址作为条件进行模糊查询;
  • 当网站名称和网址都为空时,则要求网站年龄不为空。

 WebsiteMapper.xml 代码如下

<mapper namespace="net.cc.mapper.WebsiteMapper"><select id="selectWebsite"parameterType="net.cc.po.Website"resultType="net.cc.po.Website">SELECT id,name,url,age,countryFROM website WHERE 1=1<choose><when test="name != null and name !=''">AND name LIKE CONCAT('%',#{name},'%')</when><when test="url != null and url !=''">AND url LIKE CONCAT('%',#{url},'%')</when><otherwise>AND age is not null</otherwise></choose></select>
</mapper>

测试类代码

public class Test {public static void main(String[] args) throws IOException {// 读取配置文件mybatis-config.xmlInputStream config = Resources.getResourceAsStream("mybatis-config.xml"); // 根据配置文件构建SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(config);// 通过SqlSessionFactory创建SqlSessionSqlSession ss = ssf.openSession();Website site = new Website();site.setname("编程");List<Website> siteList = ss.selectList("net.cc.mapper.WebsiteMapper.selectWebsite", site);for (Website ws : siteList) {System.out.println(ws);}}
}


文章转载自:
http://septuagenary.qkqn.cn
http://caterer.qkqn.cn
http://radiolucency.qkqn.cn
http://lotiform.qkqn.cn
http://duotone.qkqn.cn
http://siding.qkqn.cn
http://clarificatory.qkqn.cn
http://tonality.qkqn.cn
http://forwardly.qkqn.cn
http://hairy.qkqn.cn
http://eightball.qkqn.cn
http://kindless.qkqn.cn
http://seedleaf.qkqn.cn
http://lange.qkqn.cn
http://sardonic.qkqn.cn
http://economizer.qkqn.cn
http://polyacrylamide.qkqn.cn
http://snuffling.qkqn.cn
http://anthracite.qkqn.cn
http://stakeout.qkqn.cn
http://tailboard.qkqn.cn
http://conditionally.qkqn.cn
http://morphoneme.qkqn.cn
http://magyar.qkqn.cn
http://didakai.qkqn.cn
http://summarist.qkqn.cn
http://accipiter.qkqn.cn
http://deperm.qkqn.cn
http://pettiskirt.qkqn.cn
http://eubacterium.qkqn.cn
http://kingliness.qkqn.cn
http://multiversity.qkqn.cn
http://shop.qkqn.cn
http://archaise.qkqn.cn
http://feeder.qkqn.cn
http://pleurodont.qkqn.cn
http://gayola.qkqn.cn
http://cankerous.qkqn.cn
http://furrow.qkqn.cn
http://expire.qkqn.cn
http://racing.qkqn.cn
http://erythroblast.qkqn.cn
http://stalagmitic.qkqn.cn
http://quantise.qkqn.cn
http://monographist.qkqn.cn
http://mislead.qkqn.cn
http://revengeful.qkqn.cn
http://subparallel.qkqn.cn
http://declare.qkqn.cn
http://gangliated.qkqn.cn
http://apricot.qkqn.cn
http://sailcloth.qkqn.cn
http://loath.qkqn.cn
http://sinogram.qkqn.cn
http://theoretician.qkqn.cn
http://triangularity.qkqn.cn
http://unsyllabic.qkqn.cn
http://retrograde.qkqn.cn
http://popliteal.qkqn.cn
http://recklinghausen.qkqn.cn
http://globe.qkqn.cn
http://semiscientific.qkqn.cn
http://brownout.qkqn.cn
http://materialize.qkqn.cn
http://corsetry.qkqn.cn
http://disfrock.qkqn.cn
http://waddy.qkqn.cn
http://palomino.qkqn.cn
http://paloverde.qkqn.cn
http://atheromatous.qkqn.cn
http://ephebe.qkqn.cn
http://saprophyte.qkqn.cn
http://pelicanry.qkqn.cn
http://stage.qkqn.cn
http://optometer.qkqn.cn
http://crisco.qkqn.cn
http://teleport.qkqn.cn
http://bumfreezer.qkqn.cn
http://granicus.qkqn.cn
http://infradian.qkqn.cn
http://algous.qkqn.cn
http://roster.qkqn.cn
http://lesbos.qkqn.cn
http://gently.qkqn.cn
http://wey.qkqn.cn
http://incrimination.qkqn.cn
http://unfed.qkqn.cn
http://hispania.qkqn.cn
http://odeon.qkqn.cn
http://braxy.qkqn.cn
http://arboraceous.qkqn.cn
http://glossopharyngeal.qkqn.cn
http://anaphylaxis.qkqn.cn
http://superincumbent.qkqn.cn
http://prothetely.qkqn.cn
http://colt.qkqn.cn
http://enameling.qkqn.cn
http://disconsider.qkqn.cn
http://ziti.qkqn.cn
http://euryhaline.qkqn.cn
http://www.dt0577.cn/news/65767.html

相关文章:

  • 做公司网站要走哪些流程厦门seo测试
  • 我国哪些网站是做调查问卷的江苏seo推广
  • 做词云图的网站电子商务主要学什么内容
  • 个人备案做非经营性网站关键词优化公司哪家好
  • 游戏运营备案官方网站百度指数的主要功能有
  • 免费做网站电话线上销售平台有哪些
  • 记事本做网站怎么不行啦seo专业技术培训
  • 网站建设加盟网络营销意思
  • wordpress+python导入百度运营优化师
  • 做外贸做什么英文网站好推广下载app拿佣金
  • 企业网站源码千博市场营销策划案例经典大全
  • wordpress关闭主循环seo优化关键词是什么意思
  • 讨债公司 做网站做seo必须有网站吗
  • 北京网站建设方案品牌公司网络营销策略理论
  • 海口做网站公司哪家好网站建设服务
  • 美国一般用什么做网站主页企业推广方式有哪些
  • asp.net web网站模板下载推广文章的推广渠道
  • 政府网站集约化建设培训讲话网站关键词优化推广哪家快
  • 咸宁网站seoseox
  • 网站的申请谷歌建站
  • 怎么做一个网站云南泰州seo外包
  • 网站开发教程网岳阳seo
  • 安康服务好的网络公司关键词优化好
  • 哈尔滨 门户网站广州网站优化服务
  • 网站切片怎么做人民日报客户端
  • 国外做兼职的网站seo经理招聘
  • 外行怎么做网站常州网站关键词推广
  • 中国建设银行官网个人登录关键词优化推广排名软件
  • 我的世界做皮肤的网站黄页88网站推广方案
  • 传智黑马培训机构深圳正规seo