使用ORM Bee时, Condition, SuidRich的方法中, 字段是否支持使用Orders::getName的形式,避免使用静态字段串写死字段值

发布于:2024-06-10 ⋅ 阅读:(104) ⋅ 点赞:(0)

使用ORM Bee时, Condition, SuidRich的方法中, 字段是否支持使用Orders::getName的形式,避免使用静态字段串写死字段值.

可以使用V2.4.0 的ConditionExt和SuidRichExt

需要引用BeeExt.

示例代码如下:

package org.teasoft.exam.bee.osql.ext24;

import org.teasoft.bee.osql.Op;
import org.teasoft.bee.osql.api.SuidRich;
import org.teasoft.beex.osql.api.ConditionExt;
import org.teasoft.beex.osql.api.SuidRichExt;
import org.teasoft.beex.osql.shortcut.BFX;
import org.teasoft.exam.bee.osql.entity.Orders;
import org.teasoft.honey.osql.shortcut.BF;

/**
 * @author Kingstar
 * @since  2.4.0
 */
public class TestBFX {
	
	public static void main(String[] args) {
		ConditionExt conditionExt=BFX.getConditionExt();
		conditionExt.op(Orders::getAbc, Op.eq, "value11");
		SuidRich suidRich=BF.getSuidRich();
		suidRich.count(new Orders(), conditionExt);
		
		conditionExt.selectField(Orders::getAbc,Orders::getRemark);
		suidRich.select(new Orders(), conditionExt);
		
		
		SuidRichExt suidRichExt=BFX.getSuidRichExt();
		suidRichExt.select(new Orders(),Orders::getAbc,Orders::getRemark);
		
	}
	

}

日志:

[Bee] LoggerFactory Use the Logger is : org.teasoft.honey.logging.SystemLogger
[Bee] The current Level in SystemLogger is :debug
[INFO] [Bee] ========= BeeInitPreLoadService initLoad...
[INFO] [Bee] ========= Preload class PreLoadInit, load...
[INFO] [Bee] ========= Preload class ExtPreLoadInit, load...
[INFO] [Bee] -------- Bee    2.4.0 -------- 
[INFO] [Bee] -------- Honey  2.4.0 -------- 
[INFO] [Bee] -------- BeeExt 2.4.0 -------- 
[DEBUG] [Bee] ========= Bee    buildId  2.4.0.6
[DEBUG] [Bee] ========= Honey  buildId  2.4.0.6
[DEBUG] [Bee] ========= BeeExt buildId  2.4.0.6
[INFO] [Bee] ========= get the dbName via url is: MySQL
[INFO] [Bee] select fun SQL : select count(*) from orders where abc=?   [values]: value11(String)
[INFO] [Bee] select fun SQL :  ( ExecutableSql )
select count(*) from orders where abc='value11' ;
[WARN] Do not set the database info: bee.db.driverName do not config; 
[DEBUG] Use OriginalConn!
[INFO] [Bee] select SQL: select abc, remark from orders where abc=?   [values]: value11(String)
[INFO] [Bee] select SQL:  ( ExecutableSql )
select abc, remark from orders where abc='value11' ;
[INFO] [Bee]  | <--  select rows: 0
[INFO] [Bee] select SQL(selectFields) : select abc, remark from orders   [values]: 
[INFO] [Bee] select SQL(selectFields) :  ( ExecutableSql )
select abc, remark from orders
[INFO] [Bee]  | <--  select rows: 2