package com.stylefeng.guns.modular.system.controller.general; import com.stylefeng.guns.modular.system.model.TCarColor; import com.stylefeng.guns.modular.system.service.ITCarColorService; import com.stylefeng.guns.modular.system.util.ResultUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Date; @Controller @RequestMapping("/tCarColor") public class TCarColorController { private String PREFIX = "/system/tCarColor/"; @Autowired private ITCarColorService tCarColorService; /** * 跳转到车辆颜色列表页 * @return */ @RequestMapping("/showCarColor") public String showCarColor(){ return PREFIX + "tCarColor.html"; } /** * 跳转到添加页 * @return */ @RequestMapping("/tCarColor_add") public String tCarColorAdd(){ return PREFIX + "tCarColor_add.html"; } /** * 跳转到编辑页 * @param id * @param model * @return */ @RequestMapping("/tCarColor_update/{id}") public String tCarColorUpdate(@PathVariable Integer id, Model model){ TCarColor tCarColor = tCarColorService.selectById(id); model.addAttribute("item", tCarColor); return PREFIX + "tCarColor_edit.html"; } /** * 获取列表数据 * @param createTime * @param name * @param offset * @param limit * @return */ @ResponseBody @PostMapping("/list") public Object list(String createTime, String name, Integer offset, Integer limit){ try { return tCarColorService.list(createTime, name, offset, limit); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 添加数据 * @param carColor * @return */ @ResponseBody @PostMapping("/add") public Object add(TCarColor carColor){ try { carColor.setInsertTime(new Date()); carColor.setState(1); tCarColorService.insert(carColor); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 修改数据 * @param carColor * @return */ @ResponseBody @PostMapping("/update") public Object update(TCarColor carColor){ try { tCarColorService.updateById(carColor); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 删除 * @param id * @return */ @ResponseBody @PostMapping("/delete") public Object delete(Integer id){ try { TCarColor tCarColor = tCarColorService.selectById(id); tCarColor.setState(2); tCarColorService.updateById(tCarColor); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } }