From cacd30952a0fa55d7122061d0ace3d3718e22c45 Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Thu, 2 May 2024 15:54:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=A8=A1=E6=9D=BF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/conf.properties | 6 +++ pom.xml | 6 +++ src/main/java/io/xtfs/jwebfs/bean/WbFile.java | 10 ++-- .../io/xtfs/jwebfs/configure/EnvConfig.java | 17 ------- .../io/xtfs/jwebfs/web/ChErrorController.java | 46 +++++++++++++++++++ .../io/xtfs/jwebfs/web/WbFileController.java | 43 +++++++++++++++++ src/main/resources/application.properties | 19 +++++++- .../resources/mapper/webfs/WbFileMapper.xml | 2 +- src/main/resources/static/css/aa.css | 4 ++ src/main/resources/templates/wbfs/list.html | 13 ++++++ .../xtfs/jwebfs/mapper/WbFileMapperTest.java | 2 +- 11 files changed, 143 insertions(+), 25 deletions(-) create mode 100644 conf/conf.properties create mode 100644 src/main/java/io/xtfs/jwebfs/web/ChErrorController.java create mode 100644 src/main/java/io/xtfs/jwebfs/web/WbFileController.java create mode 100644 src/main/resources/static/css/aa.css create mode 100644 src/main/resources/templates/wbfs/list.html diff --git a/conf/conf.properties b/conf/conf.properties new file mode 100644 index 0000000..b6d48a2 --- /dev/null +++ b/conf/conf.properties @@ -0,0 +1,6 @@ +# 数据库服务器配置 +type=com.alibaba.druid.pool.DruidDataSource +druid.driver-class=com.mysql.cj.jdbc.Driver +druid.url=jdbc:mysql://127.0.0.1:3306/wbfs?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 +druid.username=root +druid.password=root diff --git a/pom.xml b/pom.xml index b78054a..9cbc06e 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,12 @@ com.zaxxer HikariCP + + + org.springframework.boot + spring-boot-starter-freemarker + + org.mybatis.spring.boot diff --git a/src/main/java/io/xtfs/jwebfs/bean/WbFile.java b/src/main/java/io/xtfs/jwebfs/bean/WbFile.java index 47514ce..d6ee3dd 100644 --- a/src/main/java/io/xtfs/jwebfs/bean/WbFile.java +++ b/src/main/java/io/xtfs/jwebfs/bean/WbFile.java @@ -6,7 +6,7 @@ package io.xtfs.jwebfs.bean; public class WbFile { private Integer id; // - private String filenmae; // 文件名 + private String filename; // 文件名 private String filehash; // 文件hash public Integer getId() { @@ -17,12 +17,12 @@ public class WbFile { this.id = id; } - public String getFilenmae() { - return filenmae; + public String getFilename() { + return filename; } - public void setFilenmae(String filenmae) { - this.filenmae = filenmae; + public void setFilename(String filename) { + this.filename = filename; } public String getFilehash() { diff --git a/src/main/java/io/xtfs/jwebfs/configure/EnvConfig.java b/src/main/java/io/xtfs/jwebfs/configure/EnvConfig.java index 3f7af7b..43eddd8 100644 --- a/src/main/java/io/xtfs/jwebfs/configure/EnvConfig.java +++ b/src/main/java/io/xtfs/jwebfs/configure/EnvConfig.java @@ -29,21 +29,4 @@ public class EnvConfig { String curPath=System.getProperty("user.dir"); return curPath; } - - /** - * 文件上传临时路径 - * @return - */ - @Bean - public MultipartConfigElement multipartConfigElement(){ - MultipartConfigFactory factory = new MultipartConfigFactory(); - String tempUrl = System.getProperty("user.dir") + File.separator + "upload" + File.separator + "tmp"; - System.out.println("临时目录:" + tempUrl); - File file = new File(tempUrl); - if (!file.exists()) { - file.mkdirs(); - } - factory.setLocation(tempUrl); - return factory.createMultipartConfig(); - } } diff --git a/src/main/java/io/xtfs/jwebfs/web/ChErrorController.java b/src/main/java/io/xtfs/jwebfs/web/ChErrorController.java new file mode 100644 index 0000000..5ed5628 --- /dev/null +++ b/src/main/java/io/xtfs/jwebfs/web/ChErrorController.java @@ -0,0 +1,46 @@ +package io.xtfs.jwebfs.web; + +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.error.ErrorAttributeOptions; +import org.springframework.boot.web.servlet.error.ErrorAttributes; +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.ServletWebRequest; + +import javax.servlet.http.HttpServletRequest; + + +/** + * 系统默认错误页面 + */ + +@RestController +public class ChErrorController implements ErrorController { + + @Autowired + private ErrorAttributes errorAttributes; + + /** + * 默认错误 + */ + private static final String path_default = "/error"; + + public String getErrorPath() { + return path_default; + } + + /** + * JSON格式错误信息 + */ + @RequestMapping(value = path_default, produces = {MediaType.APPLICATION_JSON_VALUE}) + public JSONObject error(HttpServletRequest request) { + JSONObject jsonObject =new JSONObject(); + ServletWebRequest servletWebRequest = new ServletWebRequest(request); + jsonObject.put("errmsg",errorAttributes.getErrorAttributes(servletWebRequest, ErrorAttributeOptions.defaults())); + return jsonObject; + } + +} diff --git a/src/main/java/io/xtfs/jwebfs/web/WbFileController.java b/src/main/java/io/xtfs/jwebfs/web/WbFileController.java new file mode 100644 index 0000000..9a7941b --- /dev/null +++ b/src/main/java/io/xtfs/jwebfs/web/WbFileController.java @@ -0,0 +1,43 @@ +package io.xtfs.jwebfs.web; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + + +/** + * webfile 文件管理 + */ +@Controller +@RequestMapping("/wbfs") +public class WbFileController { + private static final Log log = LogFactory.getLog(WbFileController.class); + + /** + * webfs home + * @param page + * @return + */ + @RequestMapping("") + public ModelAndView wblist(@RequestParam(value = "page",defaultValue = "1") int page){ + long curts = System.currentTimeMillis(); + ModelAndView mv = new ModelAndView(); + mv.addObject("tstr",curts); + mv.setViewName("/wbfs/list"); + return mv; + } + /** + * 监视文件夹信息,如果有变动 发送变动的信息给 + * @param reqstr + * @return + */ + @PostMapping("/notify") + public int add(@RequestBody String reqstr){ + log.info("notify:"+reqstr); + return 1; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9967566..8eb1da6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -26,8 +26,25 @@ spring.servlet.multipart.location=./upload/tmp server.tomcat.max-http-form-post-size=2MB # 静态资源 -spring.mvc.static-path-pattern=/upload/** +spring.mvc.static-path-pattern=/static/** # 设置日志级别为DEBUG模式 #log4j.rootLogger=DEBUG, stdout +# 静态资源文件的配置 +#spring.web.resources.static-locations=classpath:/static +#spring.mvc.static-path-pattern=/static/** + +# freemarker 配置 +spring.freemarker.template-loader-path=classpath:/templates +spring.freemarker.suffix=.html +spring.freemarker.enabled=true +spring.freemarker.cache=false +spring.freemarker.charset=UTF-8 +spring.freemarker.content-type=text/html +spring.freemarker.expose-request-attributes=false +spring.freemarker.expose-session-attributes=false +spring.freemarker.request-context-attribute=request +spring.freemarker.settings.template_update_delay=0 +spring.freemarker.settings.default_encoding=UTF-8 +spring.freemarker.settings.classic_compatible=true diff --git a/src/main/resources/mapper/webfs/WbFileMapper.xml b/src/main/resources/mapper/webfs/WbFileMapper.xml index 9702ca1..d9aca77 100644 --- a/src/main/resources/mapper/webfs/WbFileMapper.xml +++ b/src/main/resources/mapper/webfs/WbFileMapper.xml @@ -2,7 +2,7 @@ - + id.filename,filehash wbfile diff --git a/src/main/resources/static/css/aa.css b/src/main/resources/static/css/aa.css new file mode 100644 index 0000000..afafd28 --- /dev/null +++ b/src/main/resources/static/css/aa.css @@ -0,0 +1,4 @@ +*{ + margin: 0; + padding: 0; +} \ No newline at end of file diff --git a/src/main/resources/templates/wbfs/list.html b/src/main/resources/templates/wbfs/list.html new file mode 100644 index 0000000..e08a34e --- /dev/null +++ b/src/main/resources/templates/wbfs/list.html @@ -0,0 +1,13 @@ +<#assign rootPath=springMacroRequestContext.contextPath /> + + + + + + Title + + + +${tstr} + + \ No newline at end of file diff --git a/src/test/java/io/xtfs/jwebfs/mapper/WbFileMapperTest.java b/src/test/java/io/xtfs/jwebfs/mapper/WbFileMapperTest.java index 9e9cd64..e9a5393 100644 --- a/src/test/java/io/xtfs/jwebfs/mapper/WbFileMapperTest.java +++ b/src/test/java/io/xtfs/jwebfs/mapper/WbFileMapperTest.java @@ -19,7 +19,7 @@ public class WbFileMapperTest { public void addRs() { WbFile wbFile = new WbFile(); wbFile.setFilehash("ss"); - wbFile.setFilenmae("test"); + wbFile.setFilename("test"); int rt= wbFileMapper.addRs(wbFile); System.out.println(rt); }