diff --git a/pom.xml b/pom.xml index 9d6b08d..e8fde6c 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,17 @@ - + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.2.0 + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.4.0 + diff --git a/src/main/java/com/cym/controller/page/Test.java b/src/main/java/com/cym/controller/page/Test.java new file mode 100644 index 0000000..4413d20 --- /dev/null +++ b/src/main/java/com/cym/controller/page/Test.java @@ -0,0 +1,137 @@ +package com.cym.controller.page; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.StrUtil; +import com.cym.bean.Page; +import com.cym.ext.AdminExt; +import com.cym.ext.ExampleExt; +import com.cym.model.Admin; +import com.cym.model.Example; +import com.cym.model.Goods; +import com.cym.service.AdminExampleService; +import com.cym.utils.BaseController; +import com.cym.utils.ConditionAndWrapper; +import com.cym.utils.JsonResult; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.transaction.Transactional; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import java.util.List; + +@Slf4j +@Tag(name = "测试", description = "测试相关接口") +@Controller +@RequestMapping("/test") +public class Test extends BaseController { +// @Autowired +// AdminExampleService adminExampleService; +// @GetMapping("/test") +// @Operation(summary = "测试") +// public String test(){ +// log.error("==============error"); +// List all = jpaHelper.findAll(User.class); +// return ""; +// } + + @RequestMapping("") + public ModelAndView page(ModelAndView mv, Page page,String keyword){ + ConditionAndWrapper wrapper = new ConditionAndWrapper(); + if (StrUtil.isNotBlank(keyword)) + wrapper.like(Goods::getName, keyword); + + page = jpaHelper.findPageByQuery(wrapper, page, Goods.class); + + + mv.addObject("page", page); + mv.setViewName("/test/index"); + return mv; + } + +// @RequestMapping("/page") +// public ModelAndView page(Page page,String keyword){ +// ModelAndView mv = new ModelAndView(); +// ConditionAndWrapper wrapper = new ConditionAndWrapper(); +// if (StrUtil.isNotBlank(keyword)) +// wrapper.like(Goods::getName, keyword); +// +// Page pageByQuery = jpaHelper.findPageByQuery(wrapper, page, Goods.class); +// +// +// mv.addObject("page", pageByQuery); +// mv.setViewName("/test/index"); +// return mv; +// } + + @RequestMapping("add") + @ResponseBody + public JsonResult add(Goods example) { + + jpaHelper.insertOrUpdate(example); + + return renderSuccess(); + } + + + @RequestMapping("detail") + @ResponseBody + public JsonResult detail(String id) { + Goods example = jpaHelper.findById(id, Goods.class); +// ExampleExt exampleExt = new ExampleExt(); +// BeanUtil.copyProperties(example, exampleExt); +// +// exampleExt.setAdmin(jpaHelper.findById(example.getAdminId(), Admin.class)); + + return renderSuccess(example); + } + + @Transactional + @RequestMapping("delete") + @ResponseBody + public JsonResult delete(String id) { + jpaHelper.deleteById(id, Goods.class); + + return renderSuccess(); + } + + +// @RequestMapping("index") +// public ModelAndView admin(ModelAndView modelAndView, HttpServletRequest request, String adminId) { +// +// modelAndView.setViewName("/loginExample/index"); +// return modelAndView; +// } +// +// @RequestMapping("login") +// @ResponseBody +// public JsonResult submitLogin(String name, String pass, HttpServletRequest request) { +// +// getHttpSession().removeAttribute("adminLogin"); +// +// // 用户名密码 +// Admin admin = adminExampleService.login(name, pass); +// if (admin == null) { +// return renderError("用户名密码错误"); // 用户名密码错误 +// } +// +// // 登录成功 +// admin.setAutoKey(UUID.randomUUID().toString()); // 生成自动登录code +// jpaHelper.updateById(admin); +// +// // 读取菜单 +// AdminExt adminExt = new AdminExt(); +// +// getHttpSession().setAttribute("adminLogin", adminExt); +// +// +// return renderSuccess(admin); +// } +} diff --git a/src/main/java/com/cym/model/Goods.java b/src/main/java/com/cym/model/Goods.java new file mode 100644 index 0000000..6aa02be --- /dev/null +++ b/src/main/java/com/cym/model/Goods.java @@ -0,0 +1,77 @@ +package com.cym.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +@Entity +@Schema(description = "商品") +public class Goods { + + @Id + @Schema(description = "商品ID") + public Integer id; + + @Schema(description = "商品名称") + public String name; + + @Schema(description = "商品描述") + public String description; + + @Schema(description = "商品价格") + public Double price; + + @Schema(description = "商品标题") + public String title; + + @Schema(description = "商品图片") + public String image; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } +} diff --git a/src/main/java/com/cym/model/User.java b/src/main/java/com/cym/model/User.java index 693f5de..2cede65 100644 --- a/src/main/java/com/cym/model/User.java +++ b/src/main/java/com/cym/model/User.java @@ -9,7 +9,6 @@ import jakarta.persistence.Id; import com.cym.bean.CreateTime; import com.cym.bean.InitValue; import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.SchemaProperty; @Schema(description ="用户") @Entity diff --git a/src/main/java/com/cym/service/AdminExampleService.java b/src/main/java/com/cym/service/AdminExampleService.java index 1abcd0b..46c3ca4 100644 --- a/src/main/java/com/cym/service/AdminExampleService.java +++ b/src/main/java/com/cym/service/AdminExampleService.java @@ -15,7 +15,7 @@ public class AdminExampleService { JpaHelper jpaHelper; public Admin login(String name, String pass) { - pass = SecureUtil.md5(pass); +// pass = SecureUtil.md5(pass); return jpaHelper.findOneByQuery(new ConditionAndWrapper().eq(Admin::getName, name).eq(Admin::getPass, pass), Admin.class); } diff --git a/src/main/java/com/cym/utils/MenuUtils.java b/src/main/java/com/cym/utils/MenuUtils.java index d18717d..7b3d55f 100644 --- a/src/main/java/com/cym/utils/MenuUtils.java +++ b/src/main/java/com/cym/utils/MenuUtils.java @@ -95,6 +95,12 @@ public class MenuUtils { menuCategory.getMenus().add(new Menu("adminPage/telegramSendLog?pageSize=20", "Telegram日志")); menuCategoryList.add(menuCategory); + menuCategory = new MenuCategory("测试管理", "other"); + menuCategory.getMenus().add(new Menu("test?pageSize=20", "测试")); +// menuCategory.getMenus().add(new Menu("adminPage/emailTemplate?pageSize=20", "邮件模板")); +// menuCategory.getMenus().add(new Menu("adminPage/telegramSendLog?pageSize=20", "Telegram日志")); + menuCategoryList.add(menuCategory); + return menuCategoryList; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 56d6608..21bda1a 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,6 +1,13 @@ +#spring: +# datasource: +# printsql: true +# url: jdbc:mysql://222.186.15.41:3306/cdnWebUI +# username: cdnWebUI +# password: cdnWebUI + spring: - datasource: + datasource: printsql: true - url: jdbc:mysql://222.186.15.41:3306/cdnWebUI - username: cdnWebUI - password: cdnWebUI + url: jdbc:mysql://localhost:3306/jpatest + username: root + password: 486934 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index af035c2..9f68d36 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -75,6 +75,8 @@ springdoc: packages-to-scan: com.cym.controller.webapi.admin - group: '用户端' packages-to-scan: com.cym.controller.webapi.user + - group: 'tt' + packages-to-scan: com.cym.controller.page knife4j: enable: true diff --git a/src/main/resources/static/js/test/index.js b/src/main/resources/static/js/test/index.js new file mode 100644 index 0000000..6666449 --- /dev/null +++ b/src/main/resources/static/js/test/index.js @@ -0,0 +1,113 @@ +// var menuUrl; + +$(function() { + +}) + + + +function search() { + $("input[name='pageNum']").val(1); + $("#searchForm").submit(); +} + +function add() { + $("#id").val(""); + $("#name").val(""); + $("#title").val(""); + $("#image").val(""); + $("#price").val(""); + $("#description").val(""); + + form.render(); + showWindow("添加"); +} + + +function showWindow(title) { + layer.open({ + type: 1, + title: title, + area: ['400px', '400px'], // 宽高 + content: $('#windowDiv') + }); +} + +function addOver() { + // if ($("#name").val().trim() === '') { + // layer.msg("未填写名称"); + // return; + // } + + $.ajax({ + type: 'POST', + url: ctx + 'test/add', + data: $('#addForm').serialize(), + dataType: 'json', + success: function(data) { + if (data.success) { + location.reload(); + } else { + layer.msg(data.msg); + } + }, + error: function() { + layer.alert("请求失败,请刷新重试"); + } + }); +} + +function edit(id) { + $("#id").val(id); + + $.ajax({ + type: 'GET', + url: ctx + 'test/detail', + dataType: 'json', + data: { + id: id + }, + success: function(data) { + if (data.success) { + var example = data.obj; + $("#id").val(example.id); + $("#name").val(example.name); + $("#title").val(example.title); + $("#image").val(example.image); + $("#price").val(example.price); + $("#description").val(example.description); + + form.render(); + showWindow("编辑"); + } else { + layer.msg(data.msg); + } + }, + error: function() { + layer.alert("请求失败,请刷新重试"); + } + }); +} + +function dele(id) { + if (confirm("确认删除?")) { + $.ajax({ + type: 'POST', + url: ctx + 'test/delete', + data: { + id: id + }, + dataType: 'json', + success: function(data) { + if (data.success) { + location.reload(); + } else { + layer.msg(data.msg) + } + }, + error: function() { + layer.alert("请求失败,请刷新重试"); + } + }); + } +} \ No newline at end of file diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index 5376421..c5f78b4 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -12,6 +12,11 @@ 演示模块 +
+
+ 测试模块 +
+
diff --git a/src/main/resources/templates/test/index.html b/src/main/resources/templates/test/index.html new file mode 100644 index 0000000..33e024c --- /dev/null +++ b/src/main/resources/templates/test/index.html @@ -0,0 +1,149 @@ + + + + <#include "/common.html"/> + + + + +
+ + <#include "/header.html"/> + <#include "/menu.html"/> + +
+ +
+
+ 测试 +
+ +
+
+
+ +
+ +
+ +
+ +
+
+ +
+ +
+ + + + +
+
+ + + + + + + + + + + + + <#list page.list as example> + + + + + + + + + + +
图片名称标题价格操作
${example.image} + ${example.name} + + ${example.title} + + ${example.price} + +
+ +
+
+ +
+
+
+ + <#include '/copyright.html'/> +
+
+
+ +
+ + + +
+ +<#include '/script.html'/> + + + + \ No newline at end of file