LayUi_2(SSM+LayUi增删改查分页条件查询简单Demo)

版权声明:本文为博主原创文章,未经博主允许不得转载

项目在Idea整体轮廓

LayUi_2(SSM+LayUi增删改查分页条件查询简单Demo)_第1张图片
LayUi_2(SSM+LayUi增删改查分页条件查询简单Demo)_第2张图片

1.Car.java

```package com.mr.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car {
    private Integer carId;
    private String carName;
    private String carPrice;
}

2.CarVo.java

package com.mr.vo;

import com.mr.model.Car;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@Data
@NoArgsConstructor
public class CarVo extends Car {
    // 车辆起始价格
    private String carStartPrice;
    // 车辆结束价格
    private String carEndPrice;
}

3.LayUiController.java

package com.mr.controller;

import com.github.pagehelper.PageInfo;
import com.mr.model.Car;
import com.mr.service.ILayUiService;


import com.mr.util.DataGridVo;
import com.mr.util.Page;
import com.mr.vo.CarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


/**
 *
 */
@Controller
@RequestMapping("LayUi")
public class LayUiController {
    @Autowired
    private ILayUiService layUiService;

    /**
     * 查询
     * @param
     * @return
     */
  /*  @RequestMapping("queryCar")
    @ResponseBody
    public DataGridVo queryCar(Page page){
        List cars=layUiService.queryCar(page);
        PageInfo pageCar = new PageInfo(cars);
        DataGridVo car = new DataGridVo(0,"",pageCar.getTotal(),pageCar.getList());
        return car;
    }*/

    /**
     * 查询+分页
     * @param
     * @return
     *//*
    @RequestMapping("queryCar")
    @ResponseBody
    public LayResult queryCar(Page page){
        return layUiService.queryCar(page);
    }*/
    /**
     * 查询+分页+条件查询
     */
    @RequestMapping("queryCar")
    @ResponseBody
    public DataGridVo queryCar(Page page, CarVo vo){
        PageInfo pageList = layUiService.queryCar(page,vo);
        DataGridVo pageVo = new DataGridVo();
        pageVo.setCount(pageList.getTotal());
        pageVo.setData(pageList.getList());
        return pageVo;
    }
    /**
     * 新增
     */
    @RequestMapping("addCar")
    @ResponseBody
    public String addCar(Car car){
        layUiService.addCar(car);
        return "新增成功";
    }
    /**
     * 删除
     */
    @RequestMapping("deleteCar")
    @ResponseBody
    public String  deleteCar(Integer id){
      layUiService.deleteCar(id);
       return "删除成功";
    }
    /**
     * 根据Id回显一条数据
     */
    @RequestMapping("selectByCarId")
    @ResponseBody
    public ModelAndView selectByCarId(Integer id){
       Car car  =  layUiService.selectByCarId(id);
        ModelAndView modelAndView = new ModelAndView("../../Ui/update");
        modelAndView.addObject("car",car);
        return modelAndView ;


    }
    /**
     * 修改
     *
     */
    @ResponseBody
    @RequestMapping("updateCar")
    public String updateStudent(Car car){
        try {
            layUiService.updateCar(car);
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

}``

4.ILayUiService.java


import com.github.pagehelper.PageInfo;
import com.mr.model.Car;
import com.mr.util.LayResult;
import com.mr.util.Page;
import com.mr.vo.CarVo;


/**
 *
 */
public interface ILayUiService {
    /**
     * 查询+分页
     * @param
     * @return
     */
    //LayResult queryCar(Page page);

    /**
     * 新增
     */
    void addCar(Car car);

    /**
     * 删除
     * @param id
     */
    void deleteCar(Integer id);

    /**
     * 根据Id回显一条数据
     */
    Car selectByCarId(Integer id);

    /**
     * 修改
     * @param car
     */
    void updateCar(Car car);

    /**
     * 查询+分页+条件查询
     */
    PageInfo queryCar(Page page, CarVo vo);


/**
 * 查询
 * @param
 * @return
 */
    // List queryCar(Page page);


}

5.LayUiServiceImpl.java


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mr.mapper.LayUiMapper;
import com.mr.model.Car;
import com.mr.service.ILayUiService;
import com.mr.util.LayResult;
import com.mr.util.Page;
import com.mr.vo.CarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 
 */
@Service(value="layUiService")
public class LayUiServiceImpl implements ILayUiService{
    @Autowired
    private LayUiMapper layUiMapper;

    /**
     * 查询
     * @param
     * @return
     */
   /* public List queryCar(Page page) {
        return layUiMapper.queryCar();
    }*/
    /**
     * 查询+分页
     * @param
     * @return
     */
    /*public LayResult queryCar(Page page) {
        if(page==null){
            page=new Page();
        }
        PageHelper.startPage(page.getPage(),page.getLimit());
        List cars = layUiMapper.queryCar();
        PageInfo info = new PageInfo(cars);
        LayResult carLayResult = new LayResult();
        carLayResult.setCode(0);
        carLayResult.setCount(info.getTotal());
        carLayResult.setData(info.getList());
        return  carLayResult;
    }*/

    /**
     * 新增
     */
    public void addCar(Car car) {
        layUiMapper.addCar(car);
    }

    /**
     * 删除
     * @param
     */
    public void deleteCar(Integer id) {
        layUiMapper.deleteCar(id);
    }

    /**
     * 根据Id回显一条数据
     * @param id
     * @return
     */
    public Car selectByCarId(Integer id) {
        return layUiMapper.selectByCarId(id);
    }

    public void updateCar(Car car) {
        layUiMapper.updateCar(car);
    }

    /**
     * 查询+分页+条件查询
     *
     *
     */
    public PageInfo queryCar(Page page, CarVo vo) {
        if(page ==null){
            page   = new Page();
        }

        PageHelper.startPage(page.getPage(),page.getLimit());

        List list = layUiMapper.queryCar(vo);
        PageInfo pageList  = new PageInfo(list);
        return pageList;
    }


}

6.LayUiMapper.java


import com.mr.model.Car;
import com.mr.vo.CarVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 
 */
public interface LayUiMapper {
    /**
     * 查询+分页
     * @param
     * @return
     */
   // List queryCar();

    /**
     * 新增
     * @param
     */
    void addCar(Car car);

    /**
     * 删除
     * @param
     */
    void deleteCar(Integer id);

    /**
     * 根据Id回显一条数据
     * @param id
     * @return
     */
    Car selectByCarId(Integer id);

    //修改
    void updateCar(Car car);

    /**
     * 查询+分页+条件查询
     *
     *
     */
    List queryCar(@Param("cars") CarVo vo);


    /**
     * 查询
     * @param
     * @return
     */
    //List queryCar();
}

7.LayUiMapper.XML



    

    
    
    
        insert into t_car(car_name,car_price)values(#{carName},#{carPrice})
    
    
    
    
        delete from t_car where car_id=#{carId}
    
    
    
    
    
          update t_car
          set car_name=#{carName},
          car_price=#{carPrice}
           where car_id=#{carId}
    
    
    


 

8.index.jsp

  Created by IntelliJ IDEA.
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title
    
    
    












9.list.jsp

  Created by IntelliJ IDEA.
 
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title
    
    
    



车辆名称:
车辆起始价格:
车辆结束价格:

10.add.jsp

  Created by IntelliJ IDEA.
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title
    
    
    



11.update.jsp

  Created by IntelliJ IDEA.
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title
    
    
    



前台效果展示(增删改查+条件查询+分页)

LayUi_2(SSM+LayUi增删改查分页条件查询简单Demo)_第3张图片
``

附加:main.jsp

<%--
  Created by IntelliJ IDEA.
 
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>



    
    
    layui在线调试
   <%-- --%>
    
    
    
    
    



  • 演示说明
  • 日期
  • 分页
  • 上传
  • 滑块

点击上传,或将文件拖拽到此处

<%----%>

效果展示

LayUi_2(SSM+LayUi增删改查分页条件查询简单Demo)_第4张图片

你可能感兴趣的:(LayUi)