一个简单功能流程(springboot)
根据前端的需求的路径
确定项目中@RequestMapping("admin/log") 下对应方法的映射为list
前端需要的是errno ,data,errmsg
其中data是个list包含了 total,pages,limit,page,list 其中list中包含数据库查到的数据
接着在controller中调用Serice层的接口来控制业务流程,
@RequestMapping("list") public BaseRespVo list(BasePageInfo info,String name){ LogsVO<LogVO> data=logsService.selectLogs(info,name); return BaseRespVo.ok(data); }
在ServiceImpl中使用分页插件 ,调用mapper中查询方法将结果存入一个list 返回给service结果 ,同时controller返回最终前端需要的errno ,data,errmsg 数据
LogsVO<LogVO> data=logsService.selectLogs(info,name);
public interface LogsService {
LogsVO<LogVO> selectLogs(BasePageInfo info, String name);
}
@Service public class LogsServiceImpl implements LogsService { @Autowired MarketLogMapper marketLogMapper; @Override public LogsVO<LogVO> selectLogs(BasePageInfo info, String name) { PageHelper.startPage(info.getPage(), info.getLimit()); List<LogVO> list=marketLogMapper.selectInfo(name,info.getSort(),info.getOrder()); PageInfo<LogVO> logVOPageInfo = new PageInfo<>(list); return LogsVO.data(logVOPageInfo); } }
public interface MarketLogMapper { List<LogVO> selectInfo(@Param("name") String name, @Param("sort")String sort, @Param("order")String order); }
<mapper namespace="com.cskaoyan.mapper.MarketLogMapper"> <select id="selectInfo" resultType="com.cskaoyan.bean.LogVO"> select id,admin,ip,type,action,status,result,comment,add_time as add_time , update_time as update_time,deleted from market_log <where> <if test="name!=null and name!=''"> and admin like concat("%",#{name},"%") </if> </where> </select> </mapper>(我比较差,写的不好,有啥问题多多直接)