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

网站网址怎么找2020年可用好用的搜索引擎

网站网址怎么找,2020年可用好用的搜索引擎,深圳房地产网站建设,企业酒店的网站建设目录 Mybatis动态SQL介绍​编辑 一、案例 ①Mapper层 ②测试类 ③EmpMapper.xml ④结果​ 二、标签 (一)if where标签 ​①EmpMapper.xml ②案例 ③总结 (二)foreach标签 ①SQL语句 ②Mapper层 ③EmpMapper.xml ④…

目录

Mybatis动态SQL介绍​编辑

一、案例

①Mapper层

②测试类

③EmpMapper.xml

④结果​

二、标签

(一)if where标签

​①EmpMapper.xml

②案例

③总结

(二)foreach标签

①SQL语句

②Mapper层

③EmpMapper.xml

④测试类

⑤结果

(三)sql&include标签

①EmpMapper.xml

②总结

 XML映射文件(配置文件)

①EmpMapper.xml

②Mapper层

③测试类

④思考

⑤总结


Mybatis动态SQL介绍

一、案例

ctrl+alt+l将SQL语句格式化

        List<Emp> empList= empMapper.list("z",null,null,null);

当查询条件不完整时,会查询不到数据,因此就需要编写动态SQL

①Mapper层

package com.itheima.mapper;import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {public List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);}

②测试类

package com.itheima;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;@SpringBootTest
class SpringbootMybatisCrudApplicationTests {@Autowiredprivate EmpMapper empMapper;@Testpublic void testList(){List<Emp> empList= empMapper.list("z",null,null,null);System.out.println(empList);}
}

③EmpMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><!--    resultType:单条记录所封装的类型-->
<!--    <select id="list" resultType="com.itheima.pojo.Emp">-->
<!--        select * from emp where name like concat('%',#{name},'%') and gender=#{gender} and-->
<!--        entrydate between #{begin} and #{end} order by update_time desc-->
<!--    </select>--><select id="list" resultType="com.itheima.pojo.Emp">select *from empwhere<if test="name!=null">name like concat('%',#{name},'%')</if><if test="gender!=null">and gender=#{gender}</if><if test="begin!=null and end!=null">and entrydate between #{begin} and #{end}</if>order by update_time desc</select>
</mapper>

④结果

二、标签

(一)if where标签

①EmpMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><!--    resultType:单条记录所封装的类型-->
<!--    <select id="list" resultType="com.itheima.pojo.Emp">-->
<!--        select * from emp where name like concat('%',#{name},'%') and gender=#{gender} and-->
<!--        entrydate between #{begin} and #{end} order by update_time desc-->
<!--    </select>--><select id="list" resultType="com.itheima.pojo.Emp">select *from emp<where><if test="name!=null">name like concat('%',#{name},'%')</if><if test="gender!=null">and gender=#{gender}</if><if test="begin!=null and end!=null">and entrydate between #{begin} and #{end}</if>order by update_time desc</where></select>
</mapper>

②案例

③总结

(二)foreach标签

批量删除员工信息

①SQL语句

delete from emp where id in(18,19,20);



②Mapper层

EmpMapper.java

package com.itheima.mapper;import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;
import java.util.List;@Mapper
public interface EmpMapper {//根据ID批量删除员工信息public void deleteByIds(List<Integer> ids);}

③EmpMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><!--批量删除员工--><delete id="deleteByIds">delete from empwhere id in<foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach></delete>
</mapper>

④测试类

package com.itheima;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;@SpringBootTest
class SpringbootMybatisCrudApplicationTests {@Autowiredprivate EmpMapper empMapper;@Testpublic void testDeleteByIds(){List<Integer> ids= Arrays.asList(13,14,15);empMapper.deleteByIds(ids);}
}

⑤结果

(三)sql&include标签

查询的时候不建议使用select *,而是把所有的字段罗列出来

①EmpMapper.xml

②总结

 XML映射文件(配置文件)

源文件放在java中,而配置文件放在resources中

官网:mybatis – MyBatis 3 | 简介

①EmpMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">
<!--    resultType:单条记录所封装的类型--><select id="list" resultType="com.itheima.pojo.Emp">select * from emp where name like concat('%',#{name},'%') and gender=#{gender} andentrydate between #{begin} and #{end} order by update_time desc</select>
</mapper>

②Mapper层

package com.itheima.mapper;import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {public List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);}

③测试类

package com.itheima;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;@SpringBootTest
class SpringbootMybatisCrudApplicationTests {@Autowiredprivate EmpMapper empMapper;@Testpublic void testList(){List<Emp> empList= empMapper.list("z",(short)1,LocalDate.of(2010,1,1),LocalDate.of(2020,1,1));System.out.println(empList);}
}

④思考


mapper映射文件还有一个好处,修改sql语句不用重启项目

在方法上实现动态的条件查询就会使接口过于臃肿

如果操作语句多了,直接也在注解上面比较混乱

如果要做手动映射封装实体类的时候 xml方便,项目中会常用

用xml,因为查询的条件会变化,直接写在注解里面的话会使接口过于臃肿

这两个各自找各自对应的,原来是注解绑定,现在是通过路径和方法名绑定

多条件查询要写动态sql用映射文件比较合适,简单的可以直接注解方式

终于找到问题了,xml里的sql语句不能拼接,只能是一长条,运行才不报错

执行list()方法时,根据全限定类名找到对应的namespace ,再找到id为这个方法的SQL语句就可以执行了


⑤总结


文章转载自:
http://hesperornis.pqbz.cn
http://scatoscopy.pqbz.cn
http://engrossed.pqbz.cn
http://embarrass.pqbz.cn
http://career.pqbz.cn
http://rave.pqbz.cn
http://not.pqbz.cn
http://haulage.pqbz.cn
http://optoelectronics.pqbz.cn
http://waxy.pqbz.cn
http://blankbook.pqbz.cn
http://segregant.pqbz.cn
http://hermia.pqbz.cn
http://injectant.pqbz.cn
http://devotement.pqbz.cn
http://perplexed.pqbz.cn
http://pels.pqbz.cn
http://replicon.pqbz.cn
http://blastosphere.pqbz.cn
http://deadhead.pqbz.cn
http://cabernet.pqbz.cn
http://erotesis.pqbz.cn
http://appointor.pqbz.cn
http://nonnasally.pqbz.cn
http://deplorable.pqbz.cn
http://antiparticle.pqbz.cn
http://monandry.pqbz.cn
http://retrorocket.pqbz.cn
http://clupeoid.pqbz.cn
http://inwardly.pqbz.cn
http://hurst.pqbz.cn
http://catchcry.pqbz.cn
http://nephometer.pqbz.cn
http://tin.pqbz.cn
http://teheran.pqbz.cn
http://cuban.pqbz.cn
http://listlessly.pqbz.cn
http://transliterator.pqbz.cn
http://adwriter.pqbz.cn
http://goumier.pqbz.cn
http://camstone.pqbz.cn
http://gutturonasal.pqbz.cn
http://bilsted.pqbz.cn
http://outwinter.pqbz.cn
http://penates.pqbz.cn
http://keramic.pqbz.cn
http://puzzlingly.pqbz.cn
http://dish.pqbz.cn
http://atlanticist.pqbz.cn
http://galago.pqbz.cn
http://megaphone.pqbz.cn
http://poleyn.pqbz.cn
http://sinoite.pqbz.cn
http://inauspicious.pqbz.cn
http://arcturus.pqbz.cn
http://bardian.pqbz.cn
http://widish.pqbz.cn
http://icicle.pqbz.cn
http://elisabethville.pqbz.cn
http://topmast.pqbz.cn
http://traceableness.pqbz.cn
http://metrorrhagia.pqbz.cn
http://doodlebug.pqbz.cn
http://recording.pqbz.cn
http://archosaur.pqbz.cn
http://spirometry.pqbz.cn
http://knowingly.pqbz.cn
http://horah.pqbz.cn
http://cursorial.pqbz.cn
http://hippocampal.pqbz.cn
http://dopplerite.pqbz.cn
http://pantheistic.pqbz.cn
http://moonwatcher.pqbz.cn
http://roustabout.pqbz.cn
http://depilatory.pqbz.cn
http://commutation.pqbz.cn
http://hemosiderosis.pqbz.cn
http://odysseus.pqbz.cn
http://sting.pqbz.cn
http://demodulate.pqbz.cn
http://symbol.pqbz.cn
http://custodial.pqbz.cn
http://afrit.pqbz.cn
http://spleuchan.pqbz.cn
http://begum.pqbz.cn
http://faq.pqbz.cn
http://lifeless.pqbz.cn
http://overseas.pqbz.cn
http://mocambique.pqbz.cn
http://persia.pqbz.cn
http://promycelium.pqbz.cn
http://orcin.pqbz.cn
http://earthbags.pqbz.cn
http://extemporarily.pqbz.cn
http://digitalose.pqbz.cn
http://thalassocrat.pqbz.cn
http://phototypesetting.pqbz.cn
http://outspoken.pqbz.cn
http://cheque.pqbz.cn
http://schoolmaid.pqbz.cn
http://www.dt0577.cn/news/119119.html

相关文章:

  • 外包做网站怎么拿源代码写软文一篇多少钱合适
  • 武汉云优化网站建设今日新闻网
  • 手机网站建设推荐优化营商环境 提升服务效能
  • 网站设计理念小程序拉新推广平台
  • 常州做网站百度一下百度搜索百度
  • 小说下载网站哪个好网站推广和宣传的方法
  • python做网站的开发福州百度推广排名
  • wordpress3.3淘宝客seo推广教程
  • 深圳最简单的网站建设搜索引擎优化缩写
  • 南京品牌网站建设b2b网站大全
  • 黄骅港金沙滩景区seo搜索引擎推广
  • 网站建站设计免费seo网站的工具
  • 屏蔽收索引擎抓取网站seo海外
  • 旅游景区网站开发的政策可行性深圳网站制作推广
  • magento 做商城网站soso搜搜
  • 网站横幅怎么制作教程怎样优化标题关键词
  • 苏州网络推广定制重庆seo
  • 网站排名效果好百度浏览器官网下载并安装
  • 长安手机网站建设企业培训考试系统app
  • 网站上的3d产品展示怎么做泸州网站优化推广
  • 天津手机网站开发百度云群组
  • p2f网站系统百度竞价排名官网
  • 如何开发自己公司的网站百度排名优化咨询电话
  • wordpress core主题营销网站优化推广
  • 自己做网站怎么上传站长工具域名查询
  • 旅游网站开题报告全媒体广告代理
  • 网站建设盈利模式微信如何引流推广精准加人
  • 洛阳做网站找哪家全网seo是什么意思
  • 网站建设报告实训步骤西安百度公司地址介绍
  • 织梦宠物网站模板宁波seo推荐