UserController控制器
package com.cn.user.web;
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.cn.user.domain.User;
import com.cn.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
UserService userService;
/**
* id查询
* @param id id
* @return 返回值
*/
@GetMapping("/findById")
public User findById(@RequestParam(name = "id", required = true) String id){
return userService.getById(id);
}
/**
* 分页查询
* @param pageNo 起始页
* @param pageSize 页数
* @param user 类
* @return 返回值
*/
@GetMapping("/findAll")
public IPage<User> findAll(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "3") Integer pageSize,User user){
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
//queryWrapper.lambda().eq(User::getAddress,"北京");
Page<User> userPage = new Page<>(pageNo, pageSize);
IPage<User> iPage = userService.page(userPage, queryWrapper);
return iPage;
}
}
分页@Bean配置
package com.cn.config;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
/**
* 实现 IPage分页功能 写了此 分页才生效
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
/**
* 下划线转驼峰
* @return
*/
@Bean
public ConfigurationCustomizer configurationCustomizer() {
// 函数式编程
return (configuration) -> {
// 使用mybatis-plus 内置的
configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
};
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/192828.html