胡轶钦 5 vuotta sitten
vanhempi
commit
a5b55c6765

+ 155
- 0
src/main/java/com/huiju/estateagents/controller/TdCityController.java Näytä tiedosto

@@ -0,0 +1,155 @@
1
+package com.huiju.estateagents.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.huiju.estateagents.base.ResponseBean;
7
+import com.huiju.estateagents.entity.TdCity;
8
+import com.huiju.estateagents.service.ITdCityService;
9
+import org.slf4j.Logger;
10
+import org.slf4j.LoggerFactory;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.web.bind.annotation.PathVariable;
13
+import org.springframework.web.bind.annotation.RequestBody;
14
+import org.springframework.web.bind.annotation.RequestMapping;
15
+import org.springframework.web.bind.annotation.RequestMethod;
16
+import org.springframework.web.bind.annotation.RequestParam;
17
+import org.springframework.web.bind.annotation.ResponseBody;
18
+import org.springframework.web.bind.annotation.RestController;
19
+import com.huiju.estateagents.base.BaseController;
20
+
21
+import java.util.List;
22
+
23
+/**
24
+ * <p>
25
+    *  前端控制器
26
+    * </p>
27
+ *
28
+ * @author jobob
29
+ * @since 2019-08-07
30
+ */
31
+@RestController
32
+@RequestMapping("/")
33
+public class TdCityController extends BaseController {
34
+
35
+    private final Logger logger = LoggerFactory.getLogger(TdCityController.class);
36
+
37
+    @Autowired
38
+    public ITdCityService iTdCityService;
39
+
40
+
41
+    /**
42
+     * 查询列表
43
+     * @return
44
+     */
45
+    @RequestMapping(value="/admin/tdCity",method= RequestMethod.GET)
46
+    public ResponseBean tdCityList(){
47
+        ResponseBean responseBean = new ResponseBean();
48
+        try {
49
+            List<TdCity> result = iTdCityService.selectCity();
50
+            responseBean.addSuccess(result);
51
+        }catch (Exception e){
52
+            logger.error("tdCityList -=- {}",e.toString());
53
+            responseBean.addError(e.getMessage());
54
+        }
55
+        return responseBean;
56
+    }
57
+
58
+    /**
59
+     * 查询列表
60
+     * @return
61
+     */
62
+    @RequestMapping(value="/wx/tdCity",method= RequestMethod.GET)
63
+    public ResponseBean tdCityListWx(){
64
+        ResponseBean responseBean = new ResponseBean();
65
+        try {
66
+            List<TdCity> result = iTdCityService.selectCity();
67
+            responseBean.addSuccess(result);
68
+        }catch (Exception e){
69
+            logger.error("tdCityList -=- {}",e.toString());
70
+            responseBean.addError(e.getMessage());
71
+        }
72
+        return responseBean;
73
+    }
74
+
75
+    /**
76
+     * 保存对象
77
+     * @param tdCity 实体对象
78
+     * @return
79
+     */
80
+    @RequestMapping(value="/tdCity",method= RequestMethod.POST)
81
+    public ResponseBean tdCityAdd(@RequestBody TdCity tdCity){
82
+        ResponseBean responseBean = new ResponseBean();
83
+        try {
84
+            if (iTdCityService.save(tdCity)){
85
+                responseBean.addSuccess(tdCity);
86
+            }else {
87
+                responseBean.addError("fail");
88
+            }
89
+        }catch (Exception e){
90
+            logger.error("tdCityAdd -=- {}",e.toString());
91
+            responseBean.addError(e.getMessage());
92
+        }
93
+        return responseBean;
94
+    }
95
+
96
+    /**
97
+     * 根据id删除对象
98
+     * @param id  实体ID
99
+     */
100
+    @ResponseBody
101
+    @RequestMapping(value="/tdCity/{id}", method= RequestMethod.DELETE)
102
+    public ResponseBean tdCityDelete(@PathVariable Integer id){
103
+        ResponseBean responseBean = new ResponseBean();
104
+        try {
105
+            if(iTdCityService.removeById(id)){
106
+                responseBean.addSuccess("success");
107
+            }else {
108
+                responseBean.addError("fail");
109
+            }
110
+        }catch (Exception e){
111
+            logger.error("tdCityDelete -=- {}",e.toString());
112
+            responseBean.addError(e.getMessage());
113
+        }
114
+        return responseBean;
115
+    }
116
+
117
+    /**
118
+     * 修改对象
119
+     * @param id  实体ID
120
+     * @param tdCity 实体对象
121
+     * @return
122
+     */
123
+    @RequestMapping(value="/tdCity/{id}",method= RequestMethod.PUT)
124
+    public ResponseBean tdCityUpdate(@PathVariable Integer id,
125
+                                        @RequestBody TdCity tdCity){
126
+        ResponseBean responseBean = new ResponseBean();
127
+        try {
128
+            if (iTdCityService.updateById(tdCity)){
129
+                responseBean.addSuccess(tdCity);
130
+            }else {
131
+                responseBean.addError("fail");
132
+            }
133
+        }catch (Exception e){
134
+            logger.error("tdCityUpdate -=- {}",e.toString());
135
+            responseBean.addError(e.getMessage());
136
+        }
137
+        return responseBean;
138
+    }
139
+
140
+    /**
141
+     * 根据id查询对象
142
+     * @param id  实体ID
143
+     */
144
+    @RequestMapping(value="/tdCity/{id}",method= RequestMethod.GET)
145
+    public ResponseBean tdCityGet(@PathVariable Integer id){
146
+        ResponseBean responseBean = new ResponseBean();
147
+        try {
148
+            responseBean.addSuccess(iTdCityService.getById(id));
149
+        }catch (Exception e){
150
+            logger.error("tdCityDelete -=- {}",e.toString());
151
+            responseBean.addError(e.getMessage());
152
+        }
153
+        return responseBean;
154
+    }
155
+}

+ 73
- 0
src/main/java/com/huiju/estateagents/entity/TdCity.java Näytä tiedosto

@@ -0,0 +1,73 @@
1
+package com.huiju.estateagents.entity;
2
+
3
+import java.io.Serializable;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+/**
9
+ * <p>
10
+ * 
11
+ * </p>
12
+ *
13
+ * @author jobob
14
+ * @since 2019-08-07
15
+ */
16
+@Data
17
+@EqualsAndHashCode(callSuper = false)
18
+@Accessors(chain = true)
19
+public class TdCity implements Serializable {
20
+
21
+    private static final long serialVersionUID = 1L;
22
+
23
+    /**
24
+     * 省市区名称
25
+     */
26
+    private String name;
27
+
28
+    /**
29
+     * 上级ID
30
+     */
31
+    private Integer parentid;
32
+
33
+    /**
34
+     * 简称
35
+     */
36
+    private String shortname;
37
+
38
+    /**
39
+     * 级别:0,中国;1,省分;2,市;3,区、县
40
+     */
41
+    private Integer leveltype;
42
+
43
+    /**
44
+     * 城市代码
45
+     */
46
+    private String citycode;
47
+
48
+    /**
49
+     * 邮编
50
+     */
51
+    private String zipcode;
52
+
53
+    /**
54
+     * 经度
55
+     */
56
+    private String lng;
57
+
58
+    /**
59
+     * 纬度
60
+     */
61
+    private String lat;
62
+
63
+    /**
64
+     * 拼音
65
+     */
66
+    private String pinyin;
67
+
68
+    private String status;
69
+
70
+    private String initial;
71
+
72
+
73
+}

+ 22
- 0
src/main/java/com/huiju/estateagents/mapper/TdCityMapper.java Näytä tiedosto

@@ -0,0 +1,22 @@
1
+package com.huiju.estateagents.mapper;
2
+
3
+
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import com.huiju.estateagents.entity.TdCity;
6
+import org.apache.ibatis.annotations.Mapper;
7
+
8
+import java.util.List;
9
+
10
+/**
11
+ * <p>
12
+ *  Mapper 接口
13
+ * </p>
14
+ *
15
+ * @author jobob
16
+ * @since 2019-08-07
17
+ */
18
+@Mapper
19
+public interface TdCityMapper extends BaseMapper<TdCity> {
20
+    List<TdCity> selectCity();
21
+
22
+}

+ 20
- 0
src/main/java/com/huiju/estateagents/service/ITdCityService.java Näytä tiedosto

@@ -0,0 +1,20 @@
1
+package com.huiju.estateagents.service;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.huiju.estateagents.entity.TdCity;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * <p>
11
+ *  服务类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-08-07
16
+ */
17
+public interface ITdCityService extends IService<TdCity> {
18
+    List<TdCity> selectCity();
19
+
20
+}

+ 29
- 0
src/main/java/com/huiju/estateagents/service/impl/TdCityServiceImpl.java Näytä tiedosto

@@ -0,0 +1,29 @@
1
+package com.huiju.estateagents.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.huiju.estateagents.entity.TdCity;
5
+import com.huiju.estateagents.mapper.TdCityMapper;
6
+import com.huiju.estateagents.service.ITdCityService;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Service;
9
+
10
+import java.util.List;
11
+
12
+/**
13
+ * <p>
14
+ *  服务实现类
15
+ * </p>
16
+ *
17
+ * @author jobob
18
+ * @since 2019-08-07
19
+ */
20
+@Service
21
+public class TdCityServiceImpl extends ServiceImpl<TdCityMapper, TdCity> implements ITdCityService {
22
+    @Autowired
23
+    TdCityMapper tdCityMapper;
24
+
25
+    public List<TdCity> selectCity(){
26
+        return tdCityMapper.selectCity();
27
+    }
28
+
29
+}

+ 15
- 0
src/main/resources/mapper/TdCityMapper.xml Näytä tiedosto

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.huiju.estateagents.mapper.TdCityMapper">
4
+    <select id="selectCity" resultType="com.huiju.estateagents.entity.TdCity">
5
+        SELECT
6
+	*,
7
+	LEFT(pinyin,1) AS initial
8
+FROM
9
+	td_city
10
+ORDER BY
11
+	pinyin
12
+    </select>
13
+    
14
+
15
+</mapper>