今天就跟大家聊聊有关怎么在mybatis中使用if标签,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

其一、使用
其二、使用
具体代码如下
数据库表结构和数据

实体类
package com.demo.bean;
public class Commodity {
private String name;
private String date;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "Com [name=" + name + ", date=" + date + "]";
}
}mapper层
package com.demo.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.demo.bean.Commodity;
@Mapper
public interface CommodityMapper {
List getListByDate(Commodity commodity);
List getListByStartDateAndEndDate(@Param("startDate")String startDate, @Param("endDate")String endDate);
} mapper.xml文件
注意:mybatis 等值判断的 tostring()方法 (上边代码中第二个select中的toString()方法)
controller层
package com.demo.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.demo.bean.Commodity;
import com.demo.mapper.CommodityMapper;
@RestController
public class DemoController {
@Autowired
private CommodityMapper comMapper;
@RequestMapping(value = "/commodity")
public Object commodity() {
Map map = new HashMap();
Commodity com =new Commodity();
com.setDate("2018-10-12");
map.put("res", comMapper.getListByDate(com));
return map;
}
@RequestMapping(value = "/between")
public Object commodityBetween() {
Map map = new HashMap();
map.put("res", comMapper.getListByStartDateAndEndDate("2018-10-09", "2018-10-13"));
return map;
}
} 测试
1、访问 http://localhost:9000/commodity

2、访问 http://localhost:9000/between

看完上述内容,你们对怎么在mybatis中使用if标签有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联网站建设公司行业资讯频道,感谢大家的支持。
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。