0

I want to select a result according to the search number parameter,for example, if I pass 7, I want the sql statement like select * from student where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(CREATETIME),Now in Mybatis,I try to write like this,and also change ${pd.intervalDay} to #{pd.intervalDay},but it is wrong.How to change it?

<!-- pd is hasmap type -->
<select id="selectstudentresult" parameterType="page" resultType="pd">
 select * from student 
  <where>      
   <if test="pd.intervalDay!=null">
    and  DATE_SUB(CURDATE(), INTERVAL ${pd.intervalDay} DAY) <= date(a.UPDATETIME)
    </if>
 </where>
flower
  • 2,212
  • 3
  • 29
  • 44

1 Answers1

0
<select id="selectstudentresult" parameterType="page" resultType="pd">
 select * from student 
  <where>      
   <if test="intervalDay!=null">
    and  DATE_SUB(CURDATE(), INTERVAL #{intervalDay} DAY) <= date(a.UPDATETIME)
    </if>
 </where>

Use above code,since you are sending parameter as page(pojo class),you can access the variable directly..and no need to add pd.intervalday thats not a parameter-that is result type.

Prasanna Kumar H A
  • 3,341
  • 6
  • 24
  • 52