添加除id之外所有数据 添加成功后要获取插入数据库数据的主键
<select id="selectByConditionSingle" resultMap="b randMap">
select id, brand_name, company_name, ordered, description, status
from tb_brand
<where>
<choose><!--等价于switch-->
<when test="status != null"><!--等价于case-->
status = #{status}
</when>
<when test="brandName !=null and brandName != ''"><!--等价于case-->
brand_name like #{brandName}
</when>
<when test="companyName !=null and companyName != ''"><!--等价于case-->
company_name like #{companyName}
</when>
</choose>
</where>
</select>
//3.使用接口代理对象调用方法完成增删改查的操作,获取结果
List<Brand> brandList = brandMapper.selectByConditionSingle(brand);
<!--
添加品牌信息
insert标签的useGeneratedKeys属性:设置是否获取自动生成的id值的
true: 获取自动生成的id值
false: 不需要自动生成的id值
keyProperty属性: 指定获取到的id值封装到对象的哪个字段
keyColumn属性: 指定sql语句中的哪个字段代表的id
-->
<insert id="addBrand" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
insert into tb_brand(brand_name, company_name, ordered, description, status)
values (#{brandName},#{companyName},#{ordered},#{description},#{status})
</insert>