oracle+mybatis

网友投稿 713 2022-12-21

oracle+mybatis

oracle+mybatis

今天蠢了一上午才弄出这玩意,话不多说上代码!

1、建一个配置

package com.sie.demo.config;

import com.baomidou.mybatisplus.annotation.DbType;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

/**

* @author liaozhifeng

* @date 2021/7/31 11:14

* @Version 1.0

*/

@Configuration

@ConditionalOnClass(value = {PaginationInterceptor.class})

public class MybatisPlusConfig {

// 最新版

@Bean

public MybatisPlusInterceptor mybatisPlusInterceptor() {

MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

// 数据库的配置DbType.ORACLE 根据自己的数据库选择

interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));

return interceptor;

}

}

2、service层的代码

package com.sie.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sie.demo.entity.Users;

import com.sie.demo.entity.vo.PageUserVo;

import com.sie.demo.mapper.UserMapper;

import com.sie.demo.service.UserService;

import lombokhttp://.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

import org.springframework.util.DigestUtils;

import javax.annotation.Resource;

import javax.servlet.http.HttpSession;

import java.util.List;

/**

* @author liaozhifeng

* @date 2021/7/27 14:03

* @Version 1.0

*/

@Service

@Slf4j

public class UserServiceImpl extends ServiceImpl implements UserService {

@Resource

UserMapper userMapper;

/**

* 分页查询用户

* @param currentPage

* @param pageSize

* @return

*/

@Override

public PageUserVo selectAll(long currentPage, long pageSize) {

IPage userPage = new Page<>(currentPage, pageSize);//参数一是当前页,参数二是每页个数

IPage iPage = userMapper.selectPage(userPage, null);

List list = iPage.getRecords();

Long total = iPage.getTotal();

PageUserVo pageUserVo = new PageUserVo(list, total);

return pageUserVo;

}

}

3、controller层 RetResult是我自己定义的一个统一返回的泛型对象

package com.sie.demo.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.sie.demo.entity.RetCode;

import com.sie.demo.entity.RetResponse;

import com.sie.demo.entity.RetResult;

import com.sie.demo.entity.Users;

import com.sie.demo.entity.vo.PageUserVo;

import com.sie.demo.service.impl.UserServiceImpl;

import com.sie.demo.util.TokenUtil;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import javax.servlet.http.HttpSession;

import java.util.List;

@Controller

@RestController

@RequestMapping("user")

@Slf4j

public class UserController {

@Autowired

UserServiceImpl userService;

/**

*

*

* @param currentPage

* @param pageSize

* @return

*/

@GetMapping("selectAll")

public RetResult selectAll(long currentPage, long pageSize) {

log.info(currentPage+pageSize+"=========================");

PageUserVo pageUserVo = userService.selectAll(currentPage,pageSize);

return RetResponsIqYpnbe.makeOKRsp(pageUserVo);

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:长沙软件app开发公司(长沙软件科技有限公司)
下一篇:长沙软件app开发(长沙软件app开发招聘)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~