1
This commit is contained in:
@@ -86,7 +86,17 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<!--Knife4J:增强Swagger API文档-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>4.4.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<User> 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<Goods> 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);
|
||||
// }
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
#spring:
|
||||
# datasource:
|
||||
# printsql: true
|
||||
# url: jdbc:mysql://222.186.15.41:3306/cdnWebUI
|
||||
# username: cdnWebUI
|
||||
# password: cdnWebUI
|
||||
|
||||
spring:
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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("请求失败,请刷新重试");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,11 @@
|
||||
<a href="${ctx}/adminPage/example?pageSize=20">演示模块</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="layui-nav-child">
|
||||
<dd>
|
||||
<a href="${ctx}/test?pageSize=20">测试模块</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<#include "/common.html"/>
|
||||
<style type="text/css">
|
||||
.layui-form-label {
|
||||
width: 140px;
|
||||
}
|
||||
|
||||
.layui-input-block {
|
||||
margin-left: 170px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body class="layui-layout-body">
|
||||
<div class="layui-layout layui-layout-admin">
|
||||
|
||||
<#include "/header.html"/>
|
||||
<#include "/menu.html"/>
|
||||
|
||||
<div class="layui-body">
|
||||
<!-- 内容主体区域 -->
|
||||
<div style="padding: 15px">
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>测试</legend>
|
||||
</fieldset>
|
||||
|
||||
<form action="${ctx}/test" id="searchForm" method="post">
|
||||
<div class="layui-form">
|
||||
<div class="layui-inline">
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="add()">添加</button>
|
||||
</div>
|
||||
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label" style="width: 70px;">关键字</label>
|
||||
<div class="layui-input-inline" style="width: 150px;">
|
||||
<input type="text" name="keyword" value="${keyword}" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-inline">
|
||||
<button type="button" class="layui-btn layui-btn-sm" onclick="search()">搜索</button>
|
||||
</div>
|
||||
|
||||
|
||||
<input type="hidden" name="pageNum" value="${page.pageNum}">
|
||||
<input type="hidden" name="pageSize" value="${page.pageSize}">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="layui-table" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>图片</th>
|
||||
<th>名称</th>
|
||||
<th>标题</th>
|
||||
<th>价格</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<#list page.list as example>
|
||||
<tr>
|
||||
<td>${example.image}</td>
|
||||
<td>
|
||||
${example.name}
|
||||
</td>
|
||||
<td>
|
||||
${example.title}
|
||||
</td>
|
||||
<td>
|
||||
${example.price}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="layui-inline">
|
||||
<button class="layui-btn layui-btn-sm" onclick="edit('${example.id}')">编辑</button>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="dele('${example.id}')">删除</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</#list>
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="pageInfo"></div>
|
||||
|
||||
<#include '/copyright.html'/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="height: 0px; width: 0px; overflow: hidden;">
|
||||
<!-- 弹出框 -->
|
||||
<div class="layui-form" id="windowDiv" style="padding: 15px; display: none">
|
||||
<form id="addForm">
|
||||
<input type="hidden" name="id" id="id">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">图片</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="image" id="image" class="layui-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="name" id="name" class="layui-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="title" id="title" class="layui-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">价格</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="price" id="price" class="layui-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">描述</label>
|
||||
<div class="layui-input-inline">
|
||||
<textarea name="description" id="description" class="layui-textarea" autocomplete="off"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item center">
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="addOver()">提交</button>
|
||||
<button type="button" class="layui-btn layui-btn-sm" onclick="layer.closeAll()">关闭</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<#include '/script.html'/>
|
||||
<script src="${ctx}/js/test/index.js?v=${jsrandom}" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user