一. 内容简介
java论坛数据以及搜索接口实现
二. 软件环境
2.1 java 1.8
2.2 mysql Ver 8.0.13 for Win64 on x86_64 (MySQL Community Server - GPL)
2.3 IDEA ULTIMATE 2019.3
2.4d代码地址
三.主要流程
3.1 创建数据库,创建数据表
3.2 开始编写接口,并测试
四.具体步骤
4.1 获取数据,存入数据库中
数据来源,以及存储,都python写的
http://t.csdnimg.cn/NOsGD
4.2 接口代码
package com.ca.controller;
import com.ca.dao.FormListMapper;
import com.ca.dao.UsersMapper;
import com.ca.entity.Users;
import com.ca.vo.ResultVO;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.session.RowBounds;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("/form")
// value是详细说明,tags是标签
@Api(value = "论坛接口",tags = "论坛接口")
// 允许跨域
@CrossOrigin
public class FormList {
@Resource
private FormListMapper formListMapper;
@ApiOperation("论坛列表数据")
@RequestMapping(value = "/list",method = RequestMethod.GET)
public ResultVO getList(String type,int pageNum,int pageSize){
// 实体类,需要写好
Example example = new Example(com.ca.entity.FormList.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("type", type);
// // 分页处理
// PageHelper.startPage(pageNum, pageSize);
int start = (pageNum - 1)*pageSize;
RowBounds rowBounds = new RowBounds(start,pageSize);
List<com.ca.entity.FormList> formLists= formListMapper.selectByExampleAndRowBounds(example,rowBounds);
return new ResultVO(10000,"查询成功!",formLists);
}
@ApiOperation("论坛搜索接口")
@RequestMapping(value = "/search",method = RequestMethod.GET)
public ResultVO searchList(String word,int pageNum,int pageSize){
// 实体类,需要写好
Example example = new Example(com.ca.entity.FormList.class);
Example.Criteria criteria = example.createCriteria();
criteria.andLike("title", "%" + word + "%");
// // 分页处理
// PageHelper.startPage(pageNum, pageSize);
int start = (pageNum - 1)*pageSize;
RowBounds rowBounds = new RowBounds(start,pageSize);
List<com.ca.entity.FormList> formLists= formListMapper.selectByExampleAndRowBounds(example,rowBounds);
return new ResultVO(10000,"查询成功!",formLists);
}
}
4.3 接口测试