大哥:下面的代码,service层对象不能注入,使用时为null,请指教,谢谢。
@Component
public class SEQUENCE implements RunMethod, Plugin{
@Autowired
BocDataBaseService bocDataBaseService;
}
大哥:下面的代码,service层对象不能注入,使用时为null,请指教,谢谢。
@Component
public class SEQUENCE implements RunMethod, Plugin{
@Autowired
BocDataBaseService bocDataBaseService;
}
package com.jettech.dgt.web.util.mathFuction;
import java.util.List;
import org.nutz.el.ElException;
import org.nutz.el.opt.RunMethod;
import org.nutz.plugin.Plugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.jettech.dgt.model.BocDataBase;
import com.jettech.dgt.service.BocBaseFieldService;
import com.jettech.dgt.service.BocDataBaseService;
/**
* 函数-SEQUENCE-序列
* @author miaozuping
*
*/
@Component
public class SEQUENCE implements RunMethod, Plugin{
@Autowired
BocDataBaseService bocDataBaseService;
@Override
public boolean canWork() {
return true;
}
@Override
public Object run(List<Object> fetchParam) {
if(fetchParam.size()!=3&&fetchParam.size()!=2)
throw new ElException("sequence函数语法错误:sequence(dbName,sequName)");
Object dbName=fetchParam.get(0);
Object sequName=fetchParam.get(1);
Object doExecuted=fetchParam.size()==3?fetchParam.get(2):null;
if (dbName==null||dbName.toString().equals("")||sequName==null||sequName.toString().equals(""))
throw new ElException("sequence函数语法错误:sequence(dbName,sequName)");
String result = getSequenceValue(
String.valueOf(dbName),
String.valueOf(sequName),
doExecuted==null?false:Boolean.valueOf(String.valueOf(doExecuted))
);
return result;
}
@Override
public String fetchSelf() {
return "sequence";
}
public String getSequenceValue(String dbName, String sequName, boolean doExecuted){
BocDataBase db=bocDataBaseService.findByName(dbName);
if (db==null)
{
throw new ElException("数据库:["+dbName+"],在系统中查询不到;");
}
else
{
if (doExecuted)
{
try
{
return BocBaseFieldService.getValueBySequenceName(sequName, db.getName(), db.getDriver(), db.getUrl(), db.getUserName(), db.getPassWord())+"";
}
catch (Exception e)
{
throw new ElException(e.getMessage());
}
}
else
{
try
{
List<String> errorList=BocBaseFieldService.validateSequenceName(sequName, db.getName(), db.getDriver(), db.getUrl(), db.getUserName(), db.getPassWord());
if (!errorList.isEmpty())
{
throw new ElException(errorList.get(0));
}
}
catch (Exception e)
{
throw new ElException(e.getMessage());
}
}
}
return null;
}
}
对,通过js文件
{
"EL":{
"custom":[
"org.nutz.el.opt.custom.Max",
"org.nutz.el.opt.custom.Min",
"org.nutz.el.opt.custom.Trim",
"org.nutz.el.opt.custom.MakeUUID",
"org.nutz.el.opt.custom.DoBase64",
"org.nutz.el.opt.custom.DoURLEncoder",
"org.nutz.el.opt.custom.TimeNow",
"org.nutz.el.opt.custom.ByMake",
"com.jettech.dgt.web.util.mathFuction.IN",
"com.jettech.dgt.web.util.mathFuction.NOTIN",
"com.jettech.dgt.web.util.mathFuction.EXCEL",
"com.jettech.dgt.web.util.mathFuction.UNIONEXCEL",
"com.jettech.dgt.web.util.mathFuction.SEQUENCE",
]}
}
类似这种写法
public class SEQUENCE implements RunMethod, Plugin{
BocDataBaseService bocDataBaseService;
public BocDataBaseService getBocDataBaseService () {
if (bocDataBaseService == null)
bocDataBaseService = (BocDataBaseService)ContextLoader.getCurrentWebApplicationContext().getBean("bocDataBaseService");
}
}