基于Springboot+Element项目实战crud+分页:4_CURD程序

一、后端

1、mapper

package com.example.mapper;

import com.example.pojo.Peot;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface PeotMapper {

    @Select("select * from peom")
    public List<Peot> findAll();



    @Select("select * from peom where id=#{id}")
    public Peot peotfindById(Integer ID);





/*    //获取当前页的结果列表---用于分页
    @Select("select * from peom")
    public List<Peot> page(Integer start, Integer pageSize);*/

    //查询所有
    @Select("select * from peom")
    public List<Peot> list();

    @Delete("delete from peom where id=#{id}")
    public int deletePeot(Integer id);

    @Update("update peom set author=#{author},gender=#{gender},dynasty=#{dynasty},title=#{title} ,style=#{style} where id=#{id} ")
    public  boolean updatePeot(Peot peot);

    @Insert("insert into peom(author, gender, dynasty, title, style) values (#{author}, #{gender}, #{dynasty}, #{title}, #{style})")
    public int insert(Peot peot);

//查询
    //select * from peom  where author like '%陶%'
    //@Select("select * from peom where author like %#{author}% and style like %#{style}%")
    @Select("SELECT * FROM peom WHERE author LIKE CONCAT('%', #{author}, '%') AND style LIKE CONCAT('%', #{style}, '%')")
    public List<Peot> peotSearch(String author, String style);

}

2、service

package com.example.service;

import com.example.pojo.PageBean;
import com.example.pojo.Peot;

public interface PeotService {
    public PageBean page(Integer page, Integer pageSize);

    public int deletePeot(Integer id);

    public Peot peotfindById(Integer id);

    public boolean updatePeot(Peot peot);

    public   boolean  insertUser(Peot peot);

    public PageBean pageSearch(Integer page, Integer pageSize,String author, String style);

}
package com.example.service.impl;

import com.example.mapper.PeotMapper;
import com.example.pojo.Peot;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.example.pojo.PageBean;
import com.example.service.PeotService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PeotServivceImpl implements PeotService {
    @Autowired
    private PeotMapper peotMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize) {
        // 设置分页参数
        PageHelper.startPage(page, pageSize);
        // 执行分页查询
        List<Peot> peotList = peotMapper.list();
     //   System.out.println(peotList);

        // 获取分页结果
       // Page<Peot> p = (Page<Peot>) empList;
        PageInfo<Peot> p = new PageInfo<>(peotList);
        //封装PageBean
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值