mybatis-plus一个文本框查询多个值模糊查询分页
程序员文章站
2024-01-11 09:08:40
controller @GetMapping("/getcustomerlist") public IPage getCustomerList(@RequestParam(value = "pageNum" ) Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize,String name...
controller
@GetMapping("/getcustomerlist")
public IPage<Customer> getCustomerList(@RequestParam(value = "pageNum" ) Integer pageNum,
@RequestParam(value = "pageSize") Integer pageSize,String name) {
QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>();
IPage<Customer> page = new Page<>();
page.setCurrent(pageNum);
page.setSize(pageSize);
if(name.equals("")){
}else{
queryWrapper.like("c_name",name).or().like("c_address",name);
}
page = customerDao.selectPage(page,queryWrapper);
return page;
}
分页插件
package com.yy.util;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement//开启事务管理器
@Configuration//标识该类是配置类
@MapperScan("com.example.dao")//扫描mapper接口,目的是关联自定义的mapper接口
public class MyBatisPlusConfig {
/**
* 分页插件
* @return
*/
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
}
实体类
package com.yy.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
@Data
public class Customer {
@TableId(value = "c_id",type = IdType.AUTO)
private Integer cId;
@TableField("c_name")
private String cName;
@TableField("c_telephone")
private String cTelephone;
@TableField("c_address")
private String cAddress;
@TableField("c_remark")
private String cRemark;
@Override
public String toString() {
return "Customer [cId=" + cId + ", cName=" + cName + ", cTelephone=" + cTelephone + ", cAddress=" + cAddress + ", cRemark=" + cRemark +"]";
}
}
Dao
package com.yy.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yy.entity.Customer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface CustomerDao extends BaseMapper<Customer> {
}
service
package com.yy.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yy.entity.Customer;
import java.util.List;
public interface CustomerService extends IService<Customer> {
}
serviceImpl
package com.yy.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.dao.CustomerDao;
import com.yy.entity.Customer;
import com.yy.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerDao,Customer> implements CustomerService {
}
本文地址:https://blog.csdn.net/qq_42981242/article/details/110243966