2024/04/30(2024春季)

学习时长:5小时左右

代码行数:400行左右

博客数量:1篇

今天主要完成极限测试的内容,有关于科技政策查询的一个网页设计,要求可以多条件查询。

后端实现:

controller层

package com.itheima.limitTest.controller;

import com.itheima.limitTest.pojo.PageBean;
import com.itheima.limitTest.pojo.Policy;
import com.itheima.limitTest.pojo.Result;
import com.itheima.limitTest.service.PolicyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@Slf4j
@RequestMapping("/policy")
@RestController
public class PolicyController {
    @Autowired
    PolicyService policyService;
    @GetMapping
    public Result page(@RequestParam(defaultValue ="1") Integer page, @RequestParam(defaultValue ="10") Integer pageSize
    ,String name,String range,String document,String text)
    {
        log.info("在这里"+page+pageSize+name);
        PageBean pageBean=policyService.page(page,pageSize,name,range,document,text);
        return Result.success(pageBean);
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id)
    {
        Policy policy=policyService.getById(id);
        return Result.success(policy);
    }

}

service层:

package com.itheima.limitTest.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.limitTest.mapper.PolicyMapper;
import com.itheima.limitTest.pojo.PageBean;
import com.itheima.limitTest.pojo.Policy;
import com.itheima.limitTest.service.PolicyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class PoilcyServiceImpl implements PolicyService {
@Autowired
private PolicyMapper policyMapper;
    @Override
    public PageBean page(Integer page, Integer pageSize, String name, String range, String document, String text) {
        PageHelper.startPage(page,pageSize);//分页查询
        log.info("这里已经执行");
        List<Policy> policyList=policyMapper.list(name,range,document,text);
        log.info("这里已经执行");
        Page<Policy> p=(Page<Policy>) policyList;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public Policy getById(Integer id) {
        Policy policy=policyMapper.getById(id);
        return policy;
    }
}

mapper层:

package com.itheima.limitTest.mapper;

import com.itheima.limitTest.pojo.Policy;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PolicyMapper {

    List<Policy> list(@Param("name")String name, @Param("range")String range, @Param("document")String document, @Param("text")String text);

    @Select("select * from policy where id=#{id}")
    Policy getById(Integer id);
}

对应的xml文件

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.limitTest.mapper.PolicyMapper">
    <select id="list" resultType="com.itheima.limitTest.pojo.Policy">
        select id,
               name,
               type,
               category,
               `range`,
               document,
               form,
               organ,
               viadata,
               pubdata,
               perdata,
               field,
               theme,
               keyword,
               superior,
               precursor,
               succeed,
               state,
               pdf,
               redundancy,
               `rank`,
               policykey,
               newrank,
               year,
               newkey,
               secondtheme,
               allsum from policy
        <where>
               <if test="name!=null and name!=''">
                name like concat('%',#{name},'%')
               </if>
               <if test="range!=null and range!=''">
                and `range` like concat('%',#{range},'%')
               </if>
               <if test="document!=null and document!=''">
                and document like concat('%',#{document},'%')
               </if>
               <if test="text!=null and text!=''">
                and `text` like concat('%',#{text},'%')
               </if>
        </where>
        order by viadata desc
    </select>
</mapper>

由于前端页面还有很多的瑕疵,这里就不放出来了。

 

posted @ 2024-04-30 21:41  伐木工熊大  阅读(7)  评论(0编辑  收藏  举报