@RequestParam注解
作用:将请求参数绑定到你控制器的方法参数上(是SpringMVC中接收普通参数的注解)
语法:@RequestParam(value="参数名",required="true/false",defaultValue="")
其中:value为参数名
required:是否包含该参数,默认为true,表示该请求路径中必须包含该参数,如果不包含就报错
defaultValue:默认参数值,如果设置了该值,required=true将失效,自动为false,如果没有传该参数,就使用默认值
Mybatis中Integer值传0和‘’
select * from t_question
<where>
1=1
<if test="isnew!=null and isnew!=''>
AND isnew=#{isnew,jdbcType=Integere}
</if>
</where>
order by isnew desc,createtime desc
当我传isnew值为0时,似乎where语句不起作用,查资料可得
Mybatis Integer类型,值为0被任务是空字符串,所以当取值为0时,此时判断为空字符串
因此将mybatis中条件改为
<if test="isnew != null">
就好了!
只有string类型才需要判断是否 !=‘’,其他类型不需要判断
where 1=1??
这个1=1常用于应用程序根据用户选择项的不同拼凑where条件时用
例:web界面查询用户信息,where默认为1=1,这样用户即使不选择任何条件,sql查询也不会出错,如果用户选择了姓名,那么where变成了where 1=1 and 姓名=“姓名“
如果还选择了其他条件,就不断在where条件后追加and语句即可
如果不用1=1的话,每家一个条件,都要判断前面有没有where条件,如果没有就写where....,有就写and语句,此时使用1=1就简化了应用程序的复杂度。