选中.xml 右键 Junite 测试的时候,@Test位于这个包中 import org.junit.jupiter.api.Test;
根据条件进行查询总记录数 条件如果涉及到两个表的内容 你也就只写一个表里面的
select
count(1)
from
smbms_bill
<trim prefix="where" prefixOverrides="and | or">
<if test="productName!=null and productName!=''">
and productName like CONCAT('%',#{productName},'%')
</if>
<if test="providerId!=null and providerId>0">
and providerId=#{providerId}
</if>
<if test="isPayment!=null and isPayment>0">
and isPayment=#{isPayment}
</if>
</trim>
根据条件查询(分页)集合(虽然没有说按什么排序 但是你在最后需要写出来 order By )
select
b.id,b.billCode,b.productName,b.productDesc,b.productUnit,
b.productCount,b.totalPrice,b.isPayment,b.providerId,
b.createdBy,b.creationDate,b.modifyBy,b.modifyDate,p.proName as providerName
from
smbms_bill b,smbms_provider p
where
<trim prefixOverrides="and | or">
b.providerId=p.id
<if test="productName!=null and productName!=''">
and productName like CONCAT('%',#{productName},'%')
</if>
<if test="providerId!=null and providerId>0">
and providerId=#{providerId}
</if>
<if test="isPayment!=null and isPayment>0">
and isPayment=#{isPayment}
</if>
order by creationDate DESC,modifyDate DESC
<if test="startIndex!=null and pageSize!=null">
limit #{startIndex},#{pageSize}
</if>
</trim>
当个参数可以加上注解
查看 通过id 查询返回值Provider
<!-- Provider getById(@Param("id")Integer id) -->
<select id="getById" resultType="Provider">
SELECT
id,proCode,proName,
proDesc,proContact,
proPhone,proAddress,
proFax,createdBy,
creationDate,
modifyDate,modifyBy
FROM
smbms_provider
where
u.userRole=r.id
id=#{id}
</select>
删除 (增删改默认返回是int)
<!-- int delById(@Param("id")Integer id) -->
<delete id="delById">
delete from smbms_provider where id=#{id}
</delete>
添加
<!-- int add(Provider provider) -->
<insert id="add" parameterType="Provider">
insert into smbms_provider(proCode,proName,
proDesc,proContact,
proPhone,proAddress,
proFax,createdBy,
creationDate,
modifyDate,modifyBy)
values(#{proCode},#{proName},#{proDesc},#{proContact},#{proPhone},#{proAddress},
#{proFax},#{createdBy},#{creationDate},#{modifyDate},#{modifyBy})
</insert>
修改(虽然没有说按什么修改 但是你应该知道是根据id进行修改)
<!-- int update(Provider provider) -->
<update id="update" parameterType="Provider">
update smbms_provider
set
<trim suffixOverrides=",">
<if test="proCode != null">
proCode = #{proCode},
</if>
<if test="proName != null">
proName = #{proName},
</if>
<if test="proDesc != null">
proDesc = #{proDesc},
</if>
<if test="proContact !=null">
proContact = #{proContact},
</if>
<if test="proPhone != null">
proPhone = #{proPhone},
</if>
<if test="proAddress != null">
proAddress = #{proAddress},
</if>
<if test="proFax != null">
proFax = #{proFax},
</if>
<if test="userRole != null and userRole > 0">
userRole = #{userRole},
</if>
<if test="modifyBy != null">
modifyBy = #{modifyBy},
</if>
<if test="modifyDate != null">
modifyDate = #{modifyDate},
</if>
<if test="idPicPath != null">
idPicPath = #{idPicPath}
</if>
</trim>
where id = #{id}
</update>