【问题标题】:Using Dozer framework for object mapping in java在 Java 中使用 Dozer 框架进行对象映射
【发布时间】:2010-12-01 23:53:52
【问题描述】:

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

现在我因为以下问题而卡住了:

以下是我的课程:

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

谁能建议我如何使用推土机框架来实现它。

谢谢,

纳伦德拉

【问题讨论】:

    标签: java object mapping dozer


    【解决方案1】:

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

    Map<String,String> questionsMap=new HashMap<String,String>();
    
    for(BaseQuestion baseQuestion : questionMap.getQuestion()){
        questionMap.put(baseQuestion.getQuestion(),baseQuestion.getAnswer());
    }
    

    【讨论】:

    • 感谢您的回答 pgras。我想使用推土机 bcz 我有不同的数据类型(如上面的数据类型),必须映射到地图。
    猜你喜欢
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多