新增个人博客功能-搜索资源管理列表

因添加资源时数据太多很难筛选,添加资源管理的搜索功能进行检索

首先需要新增功能(查询所有的一级分类)
能够使搜索栏中的菜单直接下拉出所有的一级分类

                                

ResourcesDao中新增持久层接口接口:

//获取所有的一级分类名称
List<Resources> AllfirstType();

搜索博客管理列表mapper

ResourcesDao.xml文件中添加:

<!--查询所有的一级分类名称-->
<select id="AllfirstType" resultType="com.zx.blog.entity.Resources">
    select firstType from blog.t_resource group by firstType
</select>

业务层接口 在ResourcesService下添加:

//获取所有的一级分类名称
List<Resources> AllfirstType();

接口实现: 在ResourcesServiceImpl类中添加:

//获取所有的一级分类名称
@Override
public List<Resources> AllfirstType() {
    return  resourcesDao.AllfirstType();
}

搜索博客管理列表控制器

在ResourcesController类中resources方法中添加

    model.addAttribute("resources", resourcesService.AllfirstType());

完整代码如下:

@GetMapping("/resources")
public String resources(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum) {
    PageHelper.startPage(pageNum,10);
    List<Resources> listresources = resourcesService.listResources();
    PageInfo<Resources> pageInfo = new PageInfo<Resources>(listresources);
    model.addAttribute("resources", resourcesService.AllfirstType());
    model.addAttribute("pageInfo",pageInfo);
    return "admin/resources";
}

完成前后端交互

<div class="default text">分类</div>
<div class="menu">
  <div th:each="resource : ${resources}" class="item" data-value="1" th:data-value="${resource.firstType}" th:text="${resource.firstType}">一级标签</div>
</div>

运行:

                             

根据一级分类与资源名称进行搜索

ResourcesDao中新增持久层接口接口:

//搜索博客管理列表
List<Resources> searchByresourceNameAndfirstType(Resources Resources);

搜索博客管理列表mapper

ResourcesDao.xml文件中添加:

<!--搜索博客管理列表-->
<select id="searchByresourceNameAndfirstType" parameterType="com.zx.blog.entity.Resources" resultType="com.zx.blog.entity.Resources">
    <bind name="pattern" value="'%' + resourceName + '%'" />
    select * from blog.t_resource b
    <where>
        <if test="firstType != null">
            and b.firstType = #{firstType}
        </if>
        <if test="resourceName != null">
            and b.resourceName like #{pattern}
        </if>
    </where>
</select>

业务层接口 在ResourcesService下添加:

//搜索博客管理列表
List<Resources> getResourcesBySearch(Resources Resources);

接口实现: 在ResourcesServiceImpl类中添加:

//搜索博客管理列表
@Override
public List<Resources> getResourcesBySearch(Resources Resources) {
    return resourcesDao.searchByresourceNameAndfirstType(Resources);
}

管理列表控制器

在ResourcesController类中添加

//搜索博客管理列表
@PostMapping("/resources/search")
public String search(Resources resources, Model model,
                     @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum) {
    List<Resources> resourcesBySearch = resourcesService.getResourcesBySearch(resources);
    PageHelper.startPage(pageNum, 10);
    PageInfo<Resources> pageInfo = new PageInfo<>(resourcesBySearch);
    model.addAttribute("pageInfo", pageInfo);
    return "admin/resources :: resourcesList";
}

前后端交互

<div class="field">
  <button type="button" id="search-btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
</div>

//js

$("#search-btn").click(function () {
  $("[name='page']").val(0);
  loaddata();
});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值