所花时间(包括上课): |
2h |
代码量(行): |
150左右 |
搏客量(篇): |
1 |
了解到的知识点: |
spring boot |
备注(其他): |
package com.leap.jixianceshiboot.controller;
import com.leap.jixianceshiboot.entity.Policy;
import com.leap.jixianceshiboot.entity.PolicyTypeCount;
import com.leap.jixianceshiboot.service.PolicyQueryService;
import com.leap.jixianceshiboot.util.PageBean;
import com.leap.jixianceshiboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/policyQuery")
@CrossOrigin
public class PolicyQueryController {
@Autowired
private PolicyQueryService policyQueryService;
@GetMapping
public Result<PageBean<Policy>> getPolicy(
Integer pageNum,
Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String document,
@RequestParam(required = false) String organ,
@RequestParam(required = false) String text
){
PageBean<Policy> pageBean = policyQueryService.getPolicy(pageNum, pageSize, name, document, organ, text);
return Result.success(pageBean);
}
@GetMapping("/types")
public ResponseEntity<List<PolicyTypeCount>> getPolicyCountByTypes() {
List<PolicyTypeCount> counts = policyQueryService.getPolicyCountsByType();
return ResponseEntity.ok(counts);
}
@GetMapping("/Get")
public Result<PageBean<Policy>> GetPolicy1(
@RequestParam(required = false) String type
){
Integer pageNum = 1;
Integer pageSize = 8;
PageBean<Policy> pageBean = policyQueryService.getPolicy1(pageNum, pageSize, type);
return Result.success(pageBean);
}
//获取当前库中所有的政策信息
@GetMapping("getAll")
public List<Policy> getAll(){
return policyQueryService.getAll();
}
//根据名字中的关键字模糊查询
@GetMapping("/query")
public List<Policy> queryPolicy(@RequestParam(required = false) String name){
List<Policy> result = policyQueryService.queryPolicy(name);
return result;
}
}
<?xml version="1.0" encoding="UTF-8" ?>标签:12,name,RequestParam,leap,import,打卡,com,String From: https://www.cnblogs.com/pinganxile/p/18256658
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.leap.jixianceshiboot.mapper.PolicyQueryMapper">
<!--动态sql-->
<select id="getPolicy" resultType="com.leap.jixianceshiboot.entity.Policy">
select * from policy
<where>
<if test="name!=null">
name like CONCAT('%', #{name}, '%')
</if>
<if test="document!=null">
and document=#{document}
</if>
<if test="organ!=null">
and organ=#{organ}
</if>
<if test="text!=null">
and text like CONCAT('%', #{text}, '%')
</if>
</where>
</select>
<select id="findPolicyCountsByType" resultType="com.leap.jixianceshiboot.entity.PolicyTypeCount">
SELECT type, COUNT(*) as count
FROM policy
GROUP BY type
</select>
<select id="getPolicy1" resultType="com.leap.jixianceshiboot.entity.Policy">
select * from policy where type = #{type}
</select>
<select id="queryPolicy" resultType="com.leap.jixianceshiboot.entity.Policy">
SELECT * FROM policy WHERE name LIKE CONCAT('%', #{name}, '%');
</select>
<select id="getAll" resultType="com.leap.jixianceshiboot.entity.Policy">
select * from policy
</select>
</mapper>