diff --git a/src/demo/pom.xml b/src/demo/pom.xml
index 0200cfd..57e8046 100644
--- a/src/demo/pom.xml
+++ b/src/demo/pom.xml
@@ -63,7 +63,21 @@
-
+
+
+ org.apache.poi
+ poi
+ 3.17
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.17
+
+
+ org.xmlunit
+ xmlunit-core
+
com.alibaba
diff --git a/src/demo/src/main/java/com/example/demo/DemoApplication.java b/src/demo/src/main/java/com/example/demo/DemoApplication.java
index ae4d683..325960d 100644
--- a/src/demo/src/main/java/com/example/demo/DemoApplication.java
+++ b/src/demo/src/main/java/com/example/demo/DemoApplication.java
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
-@ComponentScan(basePackages = {"com.example.demo.controller", "com.example.demo.config", "com.example.demo.service.impl"})
+@ComponentScan(basePackages = {"com.example.demo.controller", "com.example.demo.config", "com.example.demo.service.impl","com.example.demo.mapper"})
@MapperScan("com.example.demo.mapper")
public class DemoApplication {
diff --git a/src/demo/src/main/java/com/example/demo/common/WechatUtil.java b/src/demo/src/main/java/com/example/demo/common/WechatUtil.java
index 65e19b8..3271718 100644
--- a/src/demo/src/main/java/com/example/demo/common/WechatUtil.java
+++ b/src/demo/src/main/java/com/example/demo/common/WechatUtil.java
@@ -1,7 +1,4 @@
package com.example.demo.common;
-;/**
- * Create by eval on 2019/3/20
- */
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -17,13 +14,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-/**
- * @ClassName WechatUtil
- * @Description TODO
- * @Author eval
- * @Date 9:44 2019/3/20
- * @Version 1.0
- */
+
public class WechatUtil {
public static JSONObject getSessionKeyOrOpenId(String code) {
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
diff --git a/src/demo/src/main/java/com/example/demo/common/ZipUtils.java b/src/demo/src/main/java/com/example/demo/common/ZipUtils.java
new file mode 100644
index 0000000..63e413e
--- /dev/null
+++ b/src/demo/src/main/java/com/example/demo/common/ZipUtils.java
@@ -0,0 +1,143 @@
+package com.example.demo.common;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class ZipUtils {
+ private static final int BUFFER_SIZE = 2 * 1024;
+
+ /**
+ * 压缩成ZIP 方法1
+ *
+ * @param srcDir 压缩文件夹路径
+ * @param out 压缩文件输出流
+ * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
+ * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
+ * @throws RuntimeException 压缩失败会抛出运行时异常
+ */
+
+ public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure)
+ throws RuntimeException {
+ long start = System.currentTimeMillis();
+ ZipOutputStream zos = null;
+ try {
+ zos = new ZipOutputStream(out);
+ File sourceFile = new File(srcDir);
+ compress(sourceFile, zos, sourceFile.getName(), KeepDirStructure);
+ long end = System.currentTimeMillis();
+ System.out.println("压缩完成,耗时:" + (end - start) + " ms");
+ } catch (Exception e) {
+ throw new RuntimeException("zip error from ZipUtils", e);
+ } finally {
+ if (zos != null) {
+ try {
+ zos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * 压缩成ZIP 方法2
+ *
+ * @param srcFiles 需要压缩的文件列表
+ * @param out 压缩文件输出流
+ * @throws RuntimeException 压缩失败会抛出运行时异常
+ */
+
+ public static void toZip(List srcFiles, OutputStream out) throws RuntimeException {
+ long start = System.currentTimeMillis();
+ ZipOutputStream zos = null;
+ try {
+ zos = new ZipOutputStream(out);
+ for (File srcFile : srcFiles) {
+ byte[] buf = new byte[BUFFER_SIZE];
+ zos.putNextEntry(new ZipEntry(srcFile.getName()));
+ int len;
+ FileInputStream in = new FileInputStream(srcFile);
+ while ((len = in.read(buf)) != -1) {
+ zos.write(buf, 0, len);
+ }
+ zos.closeEntry();
+ in.close();
+ }
+ long end = System.currentTimeMillis();
+ System.out.println("压缩完成,耗时:" + (end - start) + " ms");
+ } catch (Exception e) {
+ throw new RuntimeException("zip error from ZipUtils", e);
+ } finally {
+ if (zos != null) {
+ try {
+ zos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ /**
+ * 递归压缩方法
+ *
+ * @param sourceFile 源文件
+ * @param zos zip输出流
+ * @param name 压缩后的名称
+ * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
+ * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
+ * @throws Exception
+ */
+
+ private static void compress(File sourceFile, ZipOutputStream zos, String name,
+ boolean KeepDirStructure) throws Exception {
+ byte[] buf = new byte[BUFFER_SIZE];
+ if (sourceFile.isFile()) {
+ // 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
+ zos.putNextEntry(new ZipEntry(name));
+ // copy文件到zip输出流中
+ int len;
+ FileInputStream in = new FileInputStream(sourceFile);
+ while ((len = in.read(buf)) != -1) {
+ zos.write(buf, 0, len);
+ }
+ // Complete the entry
+ zos.closeEntry();
+ in.close();
+ } else {
+ File[] listFiles = sourceFile.listFiles();
+ if (listFiles == null || listFiles.length == 0) {
+ // 需要保留原来的文件结构时,需要对空文件夹进行处理
+ if (KeepDirStructure) {
+ // 空文件夹的处理
+ zos.putNextEntry(new ZipEntry(name + "/"));
+ // 没有文件,不需要文件的copy
+ zos.closeEntry();
+ }
+ } else {
+ for (File file : listFiles) {
+ // 判断是否需要保留原来的文件结构
+ if (KeepDirStructure) {
+ // 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
+ // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
+ compress(file, zos, name + "/" + file.getName(), KeepDirStructure);
+ } else {
+ compress(file, zos, file.getName(), KeepDirStructure);
+ }
+ }
+ }
+ }
+ }
+
+
+ public static void main(String[] args) throws Exception {
+ /** 测试压缩方法1 */
+ FileOutputStream fos1 = new FileOutputStream(new File("./test.zip"));
+ ZipUtils.toZip("C:\\Users\\1\\OneDrive - sliverki\\学习", fos1, true);
+
+ }
+}
diff --git a/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java b/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java
new file mode 100644
index 0000000..1f9b48e
--- /dev/null
+++ b/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java
@@ -0,0 +1,25 @@
+package com.example.demo.config;
+
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class LoginHandleInterceptor implements HandlerInterceptor {
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ /*
+ 登录成功后,取得用户的session
+ */
+ Object loginUser= request.getSession().getAttribute("loginUser");
+
+ if(loginUser==null){//没登陆
+ request.setAttribute("msg","没有权限,请先登录");
+ request.getRequestDispatcher("/index.html").forward(request,response);
+ return false;
+ }else{
+ return true;
+ }
+
+ }
+}
diff --git a/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java b/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java
index e7bf9fc..51cf113 100644
--- a/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java
+++ b/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java
@@ -1,6 +1,7 @@
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -11,4 +12,10 @@ public class MyMvcConfig implements WebMvcConfigurer {
registry.addViewController("/").setViewName("index");
registry.addViewController("/index.html").setViewName("index");
}
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new LoginHandleInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","dashboard","/","/login","/css/**","/js/**","/img/**");
+
+ }
}
diff --git a/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java b/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java
deleted file mode 100644
index 38b92f8..0000000
--- a/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.example.demo.config.config;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-/**
- * Web 配置类
- *
- * @author huang
- * @since 2022-03-18
- */
-@Configuration
-public class WebConfig implements WebMvcConfigurer {
- @Override
- public void addViewControllers(ViewControllerRegistry registry) {
- registry.addViewController("/").setViewName("login/login");
- }
-}
diff --git a/src/demo/src/main/java/com/example/demo/controller/ControllerText.java b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java
new file mode 100644
index 0000000..0b9de03
--- /dev/null
+++ b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java
@@ -0,0 +1,67 @@
+package com.example.demo.controller;
+
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.tags.Tags;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.jdbc.core.JdbcTemplate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@SpringBootApplication
+@Tag(name ="你的接口",description = "test")
+public class ControllerText {
+ @Operation(summary = "获取用户列表",description = "test")
+ @RequestMapping("getUser")
+
+ public Map getUser(){
+ System.out.println("微信小程序正在调用。。。");
+ Map map = new HashMap();
+ List list = new ArrayList();
+ list.add("zhangsan");
+ list.add("lisi");
+ list.add("wanger");
+ list.add("mazi");
+ map.put("list",list);
+ System.out.println("微信小程序调用完成。。。");
+ return map;
+ }
+ @Operation(summary = "获取用户表",description = "test")
+ @RequestMapping("getWord")
+ public Map getText(String word){
+ Map map = new HashMap();
+ String message = "我能力有限,不要为难我";
+ if ("后来".equals(word)) {
+ message="正在热映的后来的我们是刘若英的处女作。";
+ }else if("微信小程序".equals(word)){
+ message= "想获取更多微信小程序相关知识,请更多的阅读微信官方文档,还有其他更多微信开发相关的内容,学无止境。";
+ }else if("cauc".equals(word)){
+ message="yes";
+ }
+ map.put("message", message);
+ return map;
+ }
+
+ @Autowired
+ JdbcTemplate jct;
+ @Operation(summary = "取用户列表",description = "test")
+ @GetMapping("userslist")
+ public List