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

电子商务网站开发目的深圳海外推广

电子商务网站开发目的,深圳海外推广,海外网红营销,手机网站自助mybtis动态SQL注解 动态SQL注解脚本动态SQL方法中构建SQLSQL语句构造器 动态SQL注解 分类&#xff1a; 脚本动态SQL&#xff1a;XML配置方式的动态SQL&#xff0c;是用<script>的方式把它照搬过来&#xff0c;用注解来实现。适用于xml配置转换到注解配置方法中构建SQL&…

mybtis动态SQL注解

    • 动态SQL注解
      • 脚本动态SQL
      • 方法中构建SQL
      • SQL语句构造器

动态SQL注解

分类

  1. 脚本动态SQL:XML配置方式的动态SQL,是用<script>的方式把它照搬过来,用注解来实现。适用于xml配置转换到注解配置
  2. 方法中构建SQL:@SelectProvider 、@InsertProvider、@UpdateProvider、@DeleteProvider 这些方法的使用
  3. SQL语句构造器:实现动态 SQL 的内容

脚本动态SQL

在sql语句中加入<script></script>标签,按照之前sqlmap中的动态sql的样式书写;增删改查都一样

@Select("<script>"+ "select * from student "+ "<where>"+ "<if test =\" ssex != null\">"+ "and ssex = #{ssex}"+ "</if>"+ "<if test =\" classId != 0\"> and classid = #{classId} </if>"+ "</where>"+ "</script>")public List<Student> findStudentJiaoBean(Student s);

方法中构建SQL

注解@SelectProvider@InsertProvider@UpdateProvider@DeleteProvider

用法

  1. 创建SQL语句类:该类包含需要动态生成的SQL 语句;
  2. 创建Mapper接口类:该类和配置文件的接口文件一样,用来处理数据库操作;
  3. 利用@SelectProvider:将 SQL 语句类和 Mapper 接口类关联,利用@SelectProvider 的 type 属性和 method 属性;
  4. 测试验证:编写测试类,测试动态生成的SQL 语句是否准确。
//语法
@UpdateProvider(type = 内部类名.class,method = "方法名")eg:
@UpdateProvider(type = StudentSql.class,method = "updatestuSqlFunc")public int updateStudentFunc(Student s);class StudentSql{public String updatestuSqlFunc(Student s) {String sql = "update student set ";String sql1 = null;if(s.getBirthday() != null) {sql += "birthday = #{birthday},";}if(s.getClassId() != 0) {sql += "classid = #{classId},";}if(s.getSname() != null) {sql += "sname = #{sname},";}if(s.getSsex() != null) {sql += "ssex = #{ssex},";}sql1 = sql.substring(0, sql.length()-1);sql1 += " where sid = #{sid}";return sql1;}}

在接口中定义内部类,来构建需要的动态sql语句,比使用标签的方式结构更加清晰

SQL语句构造器

sql语句构造器的常用方法

属性名说明
SELECT开始或插入到 SELECT 子句,可以被多次调用,参数也会添加到 SELECT子句。
FROM开始或插入到 FROM 子句,可以被多次调用,参数也会添加到 FROM 子句
WHERE插入新的 WHERE 子句条件,可以多次被调用
OR / AND使用 OR / AND 来分隔当前的 WHERE 子句的条件
DELETE_FROM开始一个 delete 语句并指定需要从哪个表删除的表名。
INSERT_INTO开始一个 insert 语句并指定需要插入数据的表名
VALUES插入到 insert 语句中。第一个参数是要插入的列名,第二个参数则是该列的值。
UPDATE开始一个 update 语句并指定需要更新的表名
SET针对 update 语句,插入到 “set” 列表中
语法(都一样)@UpdateProvider(type = 内部类名.class,method = "方法名")eg:
//构造方法(查询)
@UpdateProvider(type = StudentSql.class,method = "selectstuGZQ")
public List<Student> selectStudentGZQ(Student s);//构造方法(新增)
@InsertProvider(type = StudentSql.class, method = "insertstuGZQ")
public int insertStudentGZQ(Student s);//构造方法(修改)
@UpdateProvider(type = StudentSql.class,method = "updatestuGZQ")	
public int updateStudentGZQ(Student s);//构造方法(删除)
@DeleteProvider(type = StudentSql.class,method = "deletestuGZQ")
public int deleteStudentGZQ(int sid);class StudentSql{public String selectstuGZQ(Student s) {return new SQL() {{SELECT("sid","birthday");SELECT("ssex","sname");SELECT("classid");FROM("Student");if(s.getSsex() != null) {WHERE("ssex = #{ssex}");}if(s.getClassId() != 0) {WHERE("classid = #{classId}");}}}.toString(); }public String insertstuGZQ(Student s) {return new SQL() {{INSERT_INTO("student");if(s.getSname() != null) {VALUES("sname","#{sname}");						}if(s.getBirthday() != null) {VALUES("birthday", "#{birthday}");				}if(s.getSsex() != null) {VALUES("ssex", "#{ssex}");						}if(s.getClassId() != 0) {VALUES("classid", "#{classId}");				}}}.toString();}public String updatestuGZQ(Student s) {return new SQL() {{UPDATE("student");if(s.getSname() != null) {SET("sname=#{sname}");}if(s.getBirthday() != null) {SET("birthday=#{birthday}");}if(s.getSsex() != null) {SET("ssex=#{ssex}");}if(s.getClassId() != 0) {SET("classid=#{classId}");}WHERE("sid = #{sid}");}}.toString();}public String deletestuGZQ(int sid) {return new SQL() {{DELETE_FROM("student");WHERE("sid = #{v}");}}.toString();}}

http://www.mnyf.cn/news/40036.html

相关文章:

  • 建站园百度推广培训
  • 拦截网站做跳转2023年4 5月份疫情结束吗
  • 推广做网站怎么样优化大师手机版下载
  • wordpress美女图片站主题b2b免费推广网站
  • 使用国外空间的网站网站一键收录
  • 手机网站如何测试seo网络推广机构
  • 曲阳住房和城乡建设局网站百度广告联盟app
  • 建设商业门户网站的重要免费的关键词优化软件
  • 新型建筑模板样品图片搜索引擎排名优化建议
  • 网站建设技术人员招聘深圳网络推广服务是什么
  • 滨州做网站建设seo是什么及作用
  • 怎么去找做网站的北京百度seo排名公司
  • 网站怎么做留言抖音关键词搜索排名收费
  • 域名有了主机有了如何做网站竞价代运营公司哪家好
  • 做网站如何写代码全网关键词指数查询
  • 自贡百度做网站多少钱网站开发公司
  • 做导航网站赚钱北京广告公司
  • 进行目的地网站建设seo技巧与技术
  • 做外汇有哪些正规的网站企业关键词大全
  • 个人网站开发协议在线识别图片找原图
  • 生物网站建设亚马逊排名seo
  • 网站服务器和网站备案吗环球网今日疫情消息
  • 购物网站 购物车界面如何做安阳企业网站优化外包
  • 宜昌视频网站建设百度公司电话是多少
  • 南京做网站营销济南优化网页
  • 多用户网站制作百度教育小程序
  • 制作游戏的平台seo免费优化工具
  • 网站规划明细表百度竞价排名收费标准
  • 网站后台管理系统制作软件app广告投放价格表
  • wordpress作者权限seo综合查询系统