版权声明:本文为博主原创文章,未经博主允许不得转载
```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;
}
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;
}
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";
}
}
}``
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);
}
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;
}
}
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();
}
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}
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title