简体   繁体   English

在Java中使用Dozer框架进行对象映射

[英]Using Dozer framework for object mapping in java

I am using Dozer framework for my object mapping in java. 我在Java中使用Dozer框架进行对象映射。

Now I got stuck because of the following problem: 现在,由于以下问题,我陷入了困境:

Following are my classes: 以下是我的课程:

    public class BaseQuestion
    {

        public String question = "";

        public String answer = "";

       /**
        * Getter for question
        */
       public String getQuestion()
       {
         return question;
       }

       /**
        * @Setter for question
        */
       public void setQuestion(String question)
       {
         this.question = question;
       }

       /**
        * Getter for answer
        */
       public String getAnswer()
        {
            return answer;
        }

       /**
        * @Setter for answer
        */
       public void setAnswer(String answer)
       {
        this.answer = answer;
       }

      }


      public class QuestionsMap
      {
              Question[] question;

             public void setQuestion(Question[] question)
             {
               this.question = question;
             }

             public Question[] getQuestion()
             {
                return this.question;
             }
      }

 In the above classes I have to map QuestionsMap class with a HashMap as below:

   Map<String,String> questionsMap=new HashMap<String,String>();
   BaseQuestion[] question=QuestionsMap.getQuestion();
   questionsMap.put(question[0].getQuestion(),question[0].getAnswer());
   questionsMap.put(question[1].getQuestion(),question[1].getAnswer());
   questionsMap.put(question[2].getQuestion(),question[2].getAnswer());
   questionsMap.put(question[3].getQuestion(),question[3].getAnswer());

Can any one suggest how can I acheive it using dozer framework. 任何人都可以建议我如何使用推土机框架来实现它。

Thanks, 谢谢,

Narendra 纳伦德拉

Why do you want to use dozer ??? 为什么要使用推土机??? Is this what you are looking for: 这是你想要的:

Map<String,String> questionsMap=new HashMap<String,String>();

for(BaseQuestion baseQuestion : questionMap.getQuestion()){
    questionMap.put(baseQuestion.getQuestion(),baseQuestion.getAnswer());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM