当前位置 : 主页 > 网页制作 > xml >

智能标签

来源:互联网 收集:自由互联 发布时间:2021-06-13
一、ProviderDao层 //智能标签案例 //智能标签多条件查询 public ListProvider providerTest(@Param("proCode") String proCode, @Param("proName") String proName); //智能标签进行修改 public int updatePro(Provider provider)

一、ProviderDao层

   //智能标签案例
    //智能标签多条件查询
    public List<Provider> providerTest(@Param("proCode") String proCode, @Param("proName") String proName);
    //智能标签进行修改
    public int updatePro(Provider provider);
    //查询范围(数组)
    public List<Provider> getProInData(String [] proCodes);
    //查询范围(集合)
    public List<Provider> getProList(List<String> list);
    //查询范围(多个集合)
    public List<Provider> getProObject(@Param("proCodeList") List<Provider> proCodeList,@Param("proNameList") List<Provider> proNameList);

二、ProviderDao.xml小配置文件

<!--智能标签案例-->
    <!--智能标签多条件查询-->
    <select id="providerTest" resultType="com.marketsys.entity.Provider">
        select * from smbms.smbms_provider
        <where>
            <if test="proCode!=null and proCode!=‘‘">
                and proCode like concat (‘%‘,#{proCode},‘%‘)
            </if>
            <if test="proName!=null and proName!=‘‘">
                and proName like concat (‘%‘,#{proName},‘%‘)
            </if>
        </where>
    </select>
    <!--智能标签进行修改-->
    <update id="updatePro">
        update smbms_provider
        <trim prefix="SET" suffixOverrides=",">
            <!--<set>-->
                <if test="proCode!=null and proCode!=‘‘">
                    proCode=#{proCode},
                </if>
                <if test="proName!=null and proName!=‘‘">
                    proName=#{proName},
                </if>
            <!--</set>-->
        </trim>
        where id=#{id}
    </update>
    <!--查询范围(数组)-->
    <select id="getProInData" resultType="com.marketsys.entity.Provider">
        <!--select * from smbms.smbms_provider where proCode in ( ? , ? )-->
        select * from smbms.smbms_provider where proCode in
        <!--colletion 代表参数类型   open代表开头  close代表结尾  separator每一项数据分隔符  item代表每一项-->
        <foreach collection="array" open="(" close=")" separator="," item="proCode">
            #{proCode}
        </foreach>
    </select>
    <!--查询范围(集合)-->
    <select id="getProList" resultType="com.marketsys.entity.Provider">
        select * from smbms.smbms_provider
        <if test="list.size>0">
            where proCode in
            <!--colletion 代表参数类型   open代表开头  close代表结尾  separator每一项数据分隔符  item代表每一项-->
            <foreach collection="list" open="(" close=")" separator="," item="proCode">
                #{proCode}
            </foreach>
        </if>
    </select>
    <!--查询范围(多个集合)-->
    <select id="getProObject" resultType="com.marketsys.entity.Provider">
        select * from smbms.smbms_provider where proCode in
            <!--colletion 代表参数类型   open代表开头  close代表结尾  separator每一项数据分隔符  item代表每一项-->
            <foreach collection="proCodeList" open="(" close=")" separator="," item="proCode">
                #{proCode.proCode}
            </foreach>
            and proName in
            <foreach collection="proNameList" open="(" close=")" separator="," item="proName">
                #{proName.proName}
            </foreach>
    </select>

 

三、test类

public class providerTest {
    SqlSession sqlSession=MybatisUtil.getSqlSession();
    ProviderDao mapper = sqlSession.getMapper(ProviderDao.class);
    //智能标签多条件查询
    @Test
    public void getAllPro(){
        List<Provider> providers = mapper.providerTest("GZ", "深圳");
        for (Provider pro:providers) {
            System.out.println(pro.getProName());
        }
    }
    //智能标签进行修改
    @Test
    public void updatePro(){
        Provider provider=new Provider();
        provider.setId(10);
        provider.setProCode("JS_GYS012");
        provider.setProName("小南京火头军信息技术有限公司");
        int count=mapper.updatePro(provider);
        sqlSession.commit();
        System.out.println(count);
    }
    //查询范围(数组)
    @Test
    public void getInPro(){
        List<Provider> providers = mapper.getProInData(new String[]{"BJ_GYS001","BJ_GYS002"});
        for (Provider pro:providers) {
            System.out.println(pro.getProName());
        }
    }
    //查询范围(集合)
    @Test
    public void getProList(){
        List<String> list=new ArrayList<>();
        list.add("BJ_GYS002");
        list.add("BJ_GYS001");
        List<Provider> providerData=mapper.getProList(list);
        for (Provider pro:providerData) {
            System.out.println(pro.getProName());
        }
    }
    //查询范围(多个集合)
    @Test
    public void getProObject(){
        List<Provider> list =new ArrayList<Provider>();
        Provider provider=new Provider();
        provider.setProCode("BJ_GYS002");
        list.add(provider);

        List<Provider> list2 =new ArrayList<Provider>();
        Provider provider2=new Provider();
        provider2.setProName("北京纳福尔食用油有限公司");
        list2.add(provider2);
        List<Provider> providerData=mapper.getProObject(list,list2);
        for (Provider pro:providerData) {
            System.out.println(pro.getProName());
        }
    }
}
上一篇:Mabatis注解
下一篇:ini配置文件必知
网友评论