title: Call a Stored Procedure in MyBatis
body: <p>Im using SqlServer and MyBatis.</p>
  
  <p>Been looking for several examples online but nothing seems to fit my need.
  The stored_procedure Im calling accepts 5 parameters and returns 1 value- for example</p>
  
  <p>give_discount (FirstName, LastName,Gender, DateOfBirth, Age )</p>
  
  <p>all of which are strings. The stored_procedure then returns a STRING which is supposed to tell you how much discount you're entitled to.</p>
  
  <p>Those five attributes (FirstName, LastName, DateOfBirth, Age, Gender) are stored in a POJO named Person.java</p>
  
  <p>So let's say I created an instance of Person.java </p>
  
  <pre><code>Person person1 = new Person();
  person1.setFirstName("Joe");
  person1.setLastName("Higashi");
  person1.setGender("M");
  person1.setDateOfBirth("1990-01-01");
  person1.setAge("29");
  </code></pre>
  
  <p>this is my mapperXML</p>
  
  <pre><code> &lt;resultMap id = "discountValueParams"  type="com.test.Person"&gt;
        &lt;result property = "FirstName"    column = "FirstName"/&gt;
        &lt;result property = "LastName"     column = "LastName"/&gt;
        &lt;result property = "Gender"       column = "Gender"/&gt;
        &lt;result property = "DateOfBirth"  column = "DateOfBirth"/&gt;
        &lt;result property = "Age"          column = "Age"/&gt;
   &lt;/resultMap&gt;  
  </code></pre>
  
  <p>So the question is:</p>
  
  <p>How do I pass <strong>person1</strong> to my stored_procedure so it will use its currently assigned values and return a value?</p>
  
  <p>Is this correct in XML mapper?</p>
  
  <pre><code>&lt;select id = "getDiscountValue" resultType = "String" parameterType = "com.test.Person" statementType = "CALLABLE"&gt;
    {call dbo.get_discount_value(
         #{FirstName,  jdbcType = NVARCHAR},
         #{LastName,  jdbcType = NVARCHAR},
         #{Gender,  jdbcType = NVARCHAR},
         #{DateOfBirth,  jdbcType = NVARCHAR},
         #{"Age",  jdbcType = NVARCHAR}
     )}
  </code></pre>
  
  <p>And the java method is:</p>
  
  <pre><code>public String getDiscountMethod( Person person) {
  
              String discountValue= "";
  
              Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
              map.put("FirstName", person.getFirstName  );
              map.put("LastName", person.getLastName());
              map.put("Gender", person.getGender());
              map.put("DateOfBirth", person.getBday());
              map.put("Age", person.getAge());
  
              SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession();
              try {
                  XmlMapper xmlmapper = session.getMapper(XmlMapper.class);
                  discountValue= applicationMapper.getDiscountValue(map) ;
                  session.commit();
              } catch (Exception e) {
                  LOGGER.error(e);
              } finally {
                  session.close();
              }
              return discountValue;           
  </code></pre>
  
  <p>}       </p>
  
  <pre><code>mapperInterface.java
  public interface UpstreamXmlMapper {
       public String callStoredProcedure (StoredProcRef storedProcRef);
  }
  </code></pre>
  
  <p>Given these lines, how do I make the proper call? I know Im lacking and obviously may have erroneously implemented something. 
  Need proper guidance.</p>
  
  <p>Updated:</p>
  
  <p>Stored Procedure variables in SqlServer:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[get_discount_for_customer]
      @formCode nvarchar(50),
      @locationCode nvarchar(10),
      @gender nvarchar(1),
      @dateOfBirth date,
      @labResultFormId bigint
  AS
  ..SP body ..
  </code></pre>
  
  <p>**</p>
  
  <p>**</p>