|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
package com.example.controller;
|
|
2
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson2.JSON;
|
|
3
|
4
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
5
|
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
|
|
5
|
6
|
import com.example.entity.database.system.User;
|
|
|
@@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
|
|
20
|
21
|
import org.springframework.web.multipart.MultipartFile;
|
|
21
|
22
|
|
|
22
|
23
|
import javax.servlet.http.HttpServletResponse;
|
|
|
24
|
+import java.io.IOException;
|
|
|
25
|
+import java.io.PrintWriter;
|
|
23
|
26
|
import java.util.*;
|
|
24
|
27
|
import java.util.stream.Collectors;
|
|
25
|
28
|
|
|
|
@@ -46,7 +49,7 @@ public class HomeController extends BaseController {
|
|
46
|
49
|
}
|
|
47
|
50
|
|
|
48
|
51
|
@ApiOperation("导出Excel")
|
|
49
|
|
- @GetMapping("/exportExcel")
|
|
|
52
|
+ @GetMapping("/exportexcel")
|
|
50
|
53
|
public void ExportExcel(HttpServletResponse response) {
|
|
51
|
54
|
List<User> list = userService.getList();
|
|
52
|
55
|
ExcelHelper<User> excel = new ExcelHelper<>(User.class);
|
|
|
@@ -54,7 +57,7 @@ public class HomeController extends BaseController {
|
|
54
|
57
|
}
|
|
55
|
58
|
|
|
56
|
59
|
@ApiOperation("导入Excel")
|
|
57
|
|
- @PostMapping("/importExcel")
|
|
|
60
|
+ @PostMapping("/importexcel")
|
|
58
|
61
|
public AjaxResult importExcel(@RequestPart MultipartFile file) throws Exception {
|
|
59
|
62
|
ExcelHelper<User> excel = new ExcelHelper<>(User.class);
|
|
60
|
63
|
List<User> list = excel.importExcel(file.getInputStream());
|
|
|
@@ -152,13 +155,28 @@ public class HomeController extends BaseController {
|
|
152
|
155
|
}
|
|
153
|
156
|
|
|
154
|
157
|
@ApiOperation("代码生成")
|
|
155
|
|
- @GetMapping("/GetCode")
|
|
|
158
|
+ @GetMapping("/getcode")
|
|
156
|
159
|
public void GetCode(HttpServletResponse response, CodeInput input) {
|
|
157
|
160
|
Map<String, Object> table = SqlRunner.db().selectOne("select table_name,table_comment from information_schema.tables"
|
|
158
|
|
- + " where table_schema = (select database()) AND table_name ='" + input.getTableName() + "' ");
|
|
|
161
|
+ + " where table_schema = (select database()) AND table_name = {0} ",input.getTableName());
|
|
|
162
|
+ if (table == null) {
|
|
|
163
|
+ Map map = new HashMap();
|
|
|
164
|
+ map.put("state", "error");
|
|
|
165
|
+ map.put("message", "此表不存在");
|
|
|
166
|
+
|
|
|
167
|
+ try {
|
|
|
168
|
+ PrintWriter out = response.getWriter();
|
|
|
169
|
+ out.write(JSON.toJSONString(map));
|
|
|
170
|
+ out.flush();
|
|
|
171
|
+ out.close();
|
|
|
172
|
+ } catch (IOException ex) {
|
|
|
173
|
+ throw new RuntimeException(ex);
|
|
|
174
|
+ }
|
|
|
175
|
+ return;
|
|
|
176
|
+ }
|
|
159
|
177
|
List<Map<String, Object>> columns = SqlRunner.db().selectList("select column_name,data_type,column_type,is_nullable,"
|
|
160
|
178
|
+ "column_key,column_comment from information_schema.columns where table_schema = (select database()) "
|
|
161
|
|
- + "and table_name = '" + input.getTableName() + "' order by ordinal_position");
|
|
|
179
|
+ + "and table_name = {0} order by ordinal_position",input.getTableName());
|
|
162
|
180
|
CodeHelper.GetCode(response, table, columns, input.getPackageName(), input.getControllerName());
|
|
163
|
181
|
}
|
|
164
|
182
|
}
|