室内设计小程序开发-创造独特的空间体验
518
2023-07-03
mybatis if标签使用总结
在项目开发中,mybatis
其一、使用
其二、使用
具体代码如下
数据库表结构和数据
实体类
package com.demo.bean;
public clhttp://ass 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;
}
http://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
List
}
mapper.xml文件
select * from commodity where 1 = 1
and date = #{date}
select * from commodity where 1 = 1
and date between #{startDate} and #{endDate}
注意: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
Commodity com =new Commodity();
com.setDate("2018-10-12");
map.put("res", comMapper.getListByDate(com));
return map;
}
@RequestMapping(value = "/between")
public Object commodityBetwbROIlrjCSeen() {
Map
map.put("res", comMapper.getListByStartDateAndEndDate("2018-10-09", "2018-10-13"));
return map;
}
}
测试
1、访问 http://localhost:9000/commodity
2、访问 http://localhost:9000/between
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~