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

网站建设要注意哪些问题西安网是科技发展有限公司

网站建设要注意哪些问题,西安网是科技发展有限公司,北京网站怎么优化,wordpress后台编辑框 自定义按钮注解作用SelectProvider动态查询SQLInsertProvider动态新增SQLUpdateProvider动态更新SQLDeleteProvider动态删除SQL Select 与 SelectProvider 只是在定义注解的方式上有所不同, 一个是静态SQL, 一个是动态SQL 。 SelectProvider 是 MyBatis 中的一个注解,用于指定…
注解作用
@SelectProvider动态查询SQL
@InsertProvider动态新增SQL
@UpdateProvider动态更新SQL
@DeleteProvider动态删除SQL

@Select 与 @SelectProvider 只是在定义注解的方式上有所不同, 一个是静态SQL, 一个是动态SQL 。

@SelectProvider 是 MyBatis 中的一个注解,用于指定一个类或者类的某个方法提供 SQL 查询语句。该注解常用于动态 SQL 的场景,例如根据不同的参数生成不同的查询语句。 使用 @SelectProvider 注解的方式可以让 MyBatis 在运行时根据注解指定的类或方法来生成对应的 SQL 查询语句,从而实现动态 SQL 功能。注解的语法如下:

@SelectProvider(type = XxxProvider.class, method = "xxxMethod")

其中,type 属性表示提供 SQL 查询语句的类,method 属性表示类中提供查询语句的方法。在查询时,MyBatis 会调用指定类中的指定方法来生成 SQL 查询语句,然后执行该查询语句并返回结果。 需要注意的是,提供 SQL 查询语句的类需要实现 org.apache.ibatis.builder.annotation.ProviderMethodResolver 接口,该接口中定义了查找提供 SQL 查询的方法的逻辑。同时,提供查询语句的方法需要返回一个字符串类型的 SQL 查询语句。 使用 @SelectProvider 注解可以让 MyBatis 的查询语句更加灵活,适用于各种复杂的查询场景。

1 @SelectProvider 使用

1 TestMapper.java

public interface TestMapper {/*** 根据性别获取老师信息** @param sex* @return* @date 2022年11月26日12点09分*/@SelectProvider(type = Test.class, method = "list")List<Teacher> list(Integer sex);}

2 Test.java

public class Test {/*** 根据性别获取老师信息** @param sex* @return* @date 2022年11月26日12点09分*/public String list(Integer sex) {return new SQL() {{SELECT("*");FROM("teacher");if (null != sex) {WHERE(" 1 = 1 sex = " + sex);} else {WHERE(" 1 = 1 ");}ORDER_BY("create_time desc");}}.toString();}}

2 模拟 Mybatis Plus

可以使用 SelectProvider 写一个适用于所有表的查询的方法。

1 BasicWrapper.java

import java.util.LinkedList;
import java.util.List;/*** @author Administrator*/
public class BasicWrapper<T> {public String last;public Class<T> bean;public String table;public String[] field;public List<String> condition = new LinkedList<>();public String orderBy;}

2 QueryWrapper.java


import java.util.Arrays;import org.apache.ibatis.jdbc.SQL;import cn.hutool.core.collection.CollectionUtil;/*** @author */
public class QueryWrapper<T> extends BasicWrapper {public QueryWrapper() {}public QueryWrapper(String table, String... field) {super.bean = null;super.table = table;super.field = (null == field || field.length == 0) ? new String[]{"*"} : field;}public String list(QueryWrapper wrapper) {Query query = wrapper.build();return new SQL() {{SELECT(query.getFields());FROM(query.getTable());WHERE(" 1 = 1 " + query.getCondition());ORDER_BY(query.getOrderBy());}}.toString();}public Query build() {Query query = new Query();query.setTable(super.table);query.setFields((null == super.field || super.field.length == 0) ? "*" : String.join(", ", Arrays.asList(super.field)));String condition = CollectionUtil.isEmpty(super.condition) ? " 1 = 1 " : String.join(" ", super.condition);String last = null == super.last ? "" : super.last;query.setCondition(condition + " " + last);return query;}public QueryWrapper orderBy(String sql) {super.orderBy = sql;return this;}public QueryWrapper orderBy(boolean condition, String sql) {if (condition) {super.orderBy = sql;}return this;}public QueryWrapper apply(String sql) {super.condition.add(" and (" + sql + ") ");return this;}public QueryWrapper apply(boolean condition, String sql) {if (condition) {super.condition.add(" and (" + sql + ") ");}return this;}public QueryWrapper eq(String filed, Object value) {super.condition.add(" and " + filed + " = " + value);return this;}public QueryWrapper eq(boolean condition, String filed, Object value) {if (condition) {if (value instanceof String) {super.condition.add(" and " + filed + " = '" + value + "'");} else {super.condition.add(" and " + filed + " = " + value);}}return this;}public QueryWrapper last(String value) {super.last = " " + value;return this;}public QueryWrapper last(boolean condition, String value) {if (condition) {super.last = " " + value;}return this;}public QueryWrapper like(String filed, Object value) {super.condition.add(" and " + filed + " like %" + value + "%");return this;}public QueryWrapper likeLeft(String filed, Object value) {super.condition.add(" and " + filed + " like %" + value + "%");return this;}public QueryWrapper likeRight(String filed, Object value) {super.condition.add(" and " + filed + " like %" + value + "%");return this;}public QueryWrapper like(boolean condition, String filed, Object value) {if (condition) {super.condition.add(" and " + filed + " like %" + value + "%");}return this;}public QueryWrapper likeLeft(boolean condition, String filed, Object value) {if (condition) {super.condition.add(" and " + filed + " like %" + value + "%");}return this;}public QueryWrapper likeRight(boolean condition, String filed, Object value) {if (condition) {super.condition.add(" and " + filed + " like %" + value + "%");}return this;}}

3 Query.java

import lombok.Data;/*** @author Administrator*/
@Data
public class Query {private String table;private String fields;private String orderBy;private String condition;}

4 Test.java

import org.apache.ibatis.jdbc.SQL;public class Test {public static void main(String agrs[]) {QueryWrapper<Teacher> wrapper = new QueryWrapper<>("teacher");wrapper.eq("sex", 1);wrapper.eq(StringUtils.isNotBlank(name), "name", name);wrapper.orderBy("create_time desc");List<Teacher> list = processMapper.list(wrapper);}}

http://www.hrbkazy.com/news/5869.html

相关文章:

  • 国栋建设网站网站优化外包
  • 江阴网站制作线在成都网站推广公司
  • 做一个旅游网站百度公司简介
  • 网站开发平台自己如何做一个网站
  • 移动app开发外包公司标题seo是什么意思
  • 家教网站建设优化seo设置
  • 在哪个网站可以查做项目中标的seo网站外链平台
  • 有做自由行包车的网站sem竞价托管费用
  • php asp网站开发教程百度指数怎么算
  • 网站建设入驻长沙网站托管seo优化公司
  • 建网站用的免费软件怎么推广网站链接
  • 宝安网站制作培训智慧软文网
  • 中国建设网站工程承包分包法珠海网站seo
  • wordpress 图书模板seo研究中心倒闭
  • 网站收录更新昆明网络推广方式有哪些
  • 南通网站建设.新浪微博指数查询
  • 不知此网站做男人也网络营销的优势与不足
  • 安卓做网站教程东莞网络优化哪家公司好
  • 青岛谷歌seo什么建站程序最利于seo
  • 网站图标ico百度竞价推广开户费用
  • 才做的网站怎么搜不到网站收录有什么用
  • 石家庄网站建设制作扬中网站制作
  • 建个人网站要多少钱百度官方网站入口
  • 文件管理宁波seo教程app推广
  • 大埔做网站社区建站网站系统
  • 微网站和手机站区别墨子学院seo
  • 网站后台页面模板下载营销型网站分析
  • 专为男人做的网站营销咨询公司
  • 在哪里建设网站爱站网站长百度查询权重
  • 网站建设的小故事金华seo全网营销