mybatisCondition查询
Condition condition = new Condition(ACurrentTotal.class);
"where t_time<=NOW() " +
"group by floor limit 1) - 60 * 10)");
Condition condition = new Condition(RRelativeCompare.class);
condition.tOrderByClau("s_date");
新生儿正常体温
condition.tOrderByClau("catagory");
⼀、单个参数:
public List<XXBean> getXXBeanList(@param("id")String id);
遗嘱的形式
<lect id="getXXXBeanList" parameterType="java.lang.String" resultType="XXBean">
lect t.* from tableName t where t.id= #{id}
</lect>
其中⽅法名和ID⼀致,#{}中的参数名与⽅法中的参数名⼀致,这⾥采⽤的是@Param这个参数,实际上@Param这个最后会被Mabatis封装为map类型的。lect 后的字段列表要和bean中的属性名⼀致,如果不⼀致的可以⽤ as 来补充。
⼆、多参数:
⽅案1
public List<XXXBean> getXXXBeanList(String xxId, String xxCode);
<lect id="getXXXBeanList" resultType="XXBean">不需要写parameterType参数
lect t.* from tableName where id = #{0} and name = #{1}
</lect>
由于是多参数那么就不能使⽤parameterType,改⽤#{index}是第⼏个就⽤第⼏个的索引,索引从0开始
⽅案2(推荐)基于注解
public List<XXXBean> getXXXBeanList(@Param("id")String id, @Param("code")String code);
<lect id="getXXXBeanList" resultType="XXBean">
lect t.* from tableName where id = #{id} and name = #{code}
</lect>
由于是多参数那么就不能使⽤parameterType,这⾥⽤@Param来指定哪⼀个
拜年短信三、Map封装多参数:
public List<XXXBean> getXXXBeanList(HashMap map);
<lect id="getXXXBeanList" parameterType="hashmap" resultType="XXBean">
lect 字段... from XXX where id=#{xxId} code = #{xxCode}
</lect>
其中hashmap是mybatis⾃⼰配置好的直接使⽤就⾏。map中key的名字是那个就在#{}使⽤那个,map如何封装就不⽤了我说了吧。
四、List封装in:
public List<XXXBean> getXXXBeanList(List<String> list);
<lect id="getXXXBeanList" resultType="XXBean">
lect 字段... from XXX where id in宝宝手脚冰凉
<foreach item="item" index="index" collection="list" open="(" parator="," clo=")">
#{item}
</foreach>
</lect>
王维字foreach 最后的效果是lect 字段... from XXX where id in ('1','2','3','4')
五、lectList()只能传递⼀个参数,但实际所需参数既要包含String类型,⼜要包含List类型时的处理⽅法:
将参数放⼊Map,再取出Map中的List遍历。如下:
那一定会很好
List<String> list_3 = new ArrayList<String>();
Map<String, Object> map2 = new HashMap<String, Object>();
list.add("1");
list.add("2");
map.put("list", list); //⽹址id
map.put("siteTag", "0");//⽹址类型
public List<SysWeb> getSysInfo(Map<String, Object> map2) {
return getSqlSession().lectList("SysInfo", map2);
橄榄油品牌
}
<lect id="getSysInfo" parameterType="java.util.Map" resultType="SysWeb">
lect t.sysSiteId, t.siteName, t1.mzNum as siteTagNum, t1.mzName as siteTag, t.url, t.iconPath from TD_WEB_SYSSITE t
left join TD_MZ_MZDY t1 Num = t.siteTag Type = 10
秋天的公园
WHERE t.siteTag = #{siteTag }
and t.sysSiteId not in
<foreach collection="list" item="item" index="index" open="(" clo=")" parator=",">
#{item}
</foreach>
</lect>