电商平台学习笔记(六)——都是Boolean惹的祸
来源:互联网 发布:工业信息化软件 编辑:程序博客网 时间:2024/04/30 02:20
Mybatis映射文件:import java.util.ArrayList;import java.util.List;import org.springframework.stereotype.Component;import cn.ilxy.bean.product.Brand;import cn.ilxy.dao.SqlsessionFactoryDefinition;@Component("brandDaoImpl")/** * 商品DAO * @author: 张荣 * @date: 2016年3月22日 */public class BrandDaoImpl extends SqlsessionFactoryDefinition implements BrandDao{public List<Brand> getBrandListWithPage(Brand brand) {List<Brand> brandList = this.getSqlSession().selectList("cn.ilxy.dao.product.BrandDao.getBrandListWithPage", brand);return brandList == null ? new ArrayList<Brand>():brandList;}}
<resultMap type="Brand" id="brand">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="imgUrl" jdbcType="VARCHAR" property="img_url" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="isDisplay" jdbcType="BOOLEAN" property="is_display" />
</resultMap>
<!-- 查询品牌 -->
<select id="getBrandListWithPage" parameterType="Brand" resultMap="brand">
SELECT id, name , description, img_url, sort , is_display
FROM bbs_brand
<where>
<if test="isDisplay != null">
is_display=#{isDisplay}
</if>
<if test="name != null">
<!-- and 只能放在这个位置,where标签可以屏蔽掉 -->
AND name=#{name}
</if>
</where>
ORDER BY id DESC LIMIT 0,5
</select>
数据库表中数据:import java.util.List;import javax.annotation.Resource;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import cn.ilxy.bean.product.Brand;import cn.ilxy.dao.product.BrandDao;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:application-context.xml")public class TestBrand {@Resource(name="brandDaoImpl")private BrandDao brandDao;public void testGetBrandListWithPage(){Brand brand = new Brand();brand.setPageNo(1);List<Brand> brandList = brandDao.getBrandListWithPage(brand);for (Brand tmp:brandList) {System.out.println(tmp.toString());}}}
is_display=#{isDisplay}
</if>
- 电商平台学习笔记(六)——都是Boolean惹的祸
- 电商平台学习笔记(七)——模板方法结合Spring在DAO层的应用
- 电商平台学习笔记(一)——Spring MVC+Mybatis分页插件
- 电商平台学习笔记(二)——List泛型常见易错点
- 电商平台学习笔记(五)——空指针异常--NullPointException
- 电商平台学习笔记(八)——面向接口编程案例分析
- shell判断全部都是数字(shell学习笔记六)
- 电商平台学习笔记(三)——Mybatis启动异常org.apache.ibatis.type.TypeException
- 电商平台学习笔记(四)——Spring配置Mybatis简化DAO层省略Mybatis核心配置文件
- js学习笔记:基本包装类型——Boolean
- PHP学习笔记——boolean布尔类型;
- UE4学习笔记(六): 次世代的移动平台渲染技术
- UE4学习笔记(六): 次世代的移动平台渲染技术
- JavaScript学习笔记——基本包装类型(上)Boolean、Number
- JAVA学习——boolean
- buildroot学习(六)——at91sam9g45软件平台更新
- 激光雷达学习笔记(六)ARM-Linux平台算法移植
- 激光雷达学习笔记(六)ARM-Linux平台算法移植
- 电商平台学习笔记(四)——Spring配置Mybatis简化DAO层省略Mybatis核心配置文件
- (OK) 运行cBPM—Fedora23
- 工具类积累(一)——Response向前台发送各种异步数据
- 电商平台学习笔记(五)——空指针异常--NullPointException
- (OK) 运行cBPM in Fedora23
- 电商平台学习笔记(六)——都是Boolean惹的祸
- day01-SpringMVC+Spring+Mybatis+Mavan+SVN环境搭建及测试
- bzoj 1602: [Usaco2008 Oct]牧场行走
- IOS自动布局中的浮动布局(6)----MyFloatLayout横空出世
- [BZOJ3038]上帝造题的七分钟2(线段树)
- TCP/IP协议:connect系统超时连接控制(2)
- 算法学习笔记(一)——全排列问题之回溯法
- JAVA容器类总结
- Android中去掉标题栏或全屏的方法