Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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();
        }
    }
}