mybatis 多条件查询
程序员文章站
2022-03-11 21:43:43
...
Controller:
AccountBean accountBean=new AccountBean();
accountBean.setAccount_id(Integer.parseInt(id));
List<AccountBean> accountBeans=getAccountService.getAccountByAid(accountBean);
Service:
public List<AccountBean> getAccountByAid(AccountBean accountBean)
{
return getAccountDao.getAccountByAid(accountBean);
}
Dao:
List<AccountBean> getAccountByAid(@Param("accountBean") AccountBean accountBean);
Mapper.xml
<select id="getAccountByAid" parameterType="com.ctrlv.suntime.simulate.comm.entity.AccountBean" resultMap="GetAccountMap">
SELECT account_id,account_code,account_name,cash_available,cash_init,cash_balance,total_value FROM sst_account
<where>
<if test="accountBean.account_id!=null">
and account_id=#{accountBean.account_id}
</if>
</where>
</select>
parameterType 对应我们的实体类 使用 <where></where> 组合查询条件 自动去除第一个and
accountBean.account_id!=null 对象名应和Dao层的对象名一致
下一篇: spring MVC整合框架