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

发布于 2024-10-05 14:16:44 字数 1671 浏览 3 评论 0原文

我正在使用 Dozer 框架在 java 中进行对象映射。

现在我因为以下问题而陷入困境:

以下是我的课程:

    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());

任何人都可以建议我如何使用推土机框架实现它。

谢谢,

纳伦德拉

I am using Dozer framework for my object mapping in java.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2024-10-12 14:16:45

为什么要使用推土机???这是您要找的吗:

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

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

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());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文