实体Entity转化为map类型

实体Entity转化为map类型
本原文链接:
http://licocom.com/archives/736

问题:如何将实体entity转化为map类型,并传给数组的方法,获取其中的某个字段

例如实体为nbcsgFile

@Autowired

private Test test:

Map entity = BeanUtils.describe(nbcsgFile);//nbcsgFile实体对象

nbcsgFile.setNbcsg01(test.getall(entity))//传值给方法getall
创建一个Test类的对象,将nbcsgFile实体转化为map传递给getall方法

在Test类中

String section = (String)entity.get(某字段);

这样section就为我们需要的实体中的某字段。

附实际开发代码:

service对应层的传递代码
Map entity = BeanUtils.describe(nbcsgFile);
nbcsgFile.setNbcsg01(this.oddNumberBasic.getAll(“nbcsg”,“nbcsg01”,entity,nbcsgFile));

对应oddNumberBasic=Test类下方法的代码
String section2 = (String)entity.get(returnTwoDan);//returnTwoDan为获取的某字段值
String section3 = (String)entity.get(returnThreeDan);//returnThreeDan为获取的某字段值
附returnTwoDan、returnThreeDan
/**

  • getTwoDan 获取默认表段2

  • */
    public String getTwoDan(String KeyTable )throws Exception{
    this.KeyTable=KeyTable.concat("_file");
    String sqlgetTwoDan=null;
    String returnTwoDan=null;

    sqlgetTwoDan=“select nbcst05 from nbcst_file where nbcst11=?”;
    Map gettwo=jdbcDao.queryForMap(sqlgetTwoDan,this.KeyTable);
    if (sqlgetTwoDan!=null){
    returnTwoDan=MapUtils.getString(gettwo,“nbcst05”);
    }else {
    throw new Exception(“段位2字段空异常”);
    }
    return returnTwoDan;
    }
    /**

  • getThreeDan 获取默认表段3

  • */
    public String getThreeDan(String KeyTable )throws Exception{
    this.KeyTable=KeyTable.concat("_file");
    String sqlgetThreeDan=null;
    String returnThreeDan=null;

    sqlgetThreeDan=“select nbcst07 from nbcst_file where nbcst11=?”;
    Map gettwo=jdbcDao.queryForMap(sqlgetThreeDan,this.KeyTable);
    if (sqlgetThreeDan!=null){
    returnThreeDan=MapUtils.getString(gettwo,“nbcst07”);
    }else {
    throw new Exception(“段位3字段空异常”);
    }
    return returnThreeDan;
    }
    以上代码都为实际开发代码,记录原理。

面向开发需求,记录学习之路♪(^∀^●)ノ

猜你喜欢

转载自blog.csdn.net/qq_42685333/article/details/83051519