This commit is contained in:
2024-09-10 11:07:52 +08:00
parent 93188a018e
commit 2c93c9fd0c
4 changed files with 26 additions and 4 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
本项目为springboot3的项目, 使用jdk21进行开发, 前端html模板为freemarker, 数据库orm为自研的jpaHelper. 本项目为springboot3的项目, 使用jdk21进行开发, 前端html模板为freemarker, 数据库orm为自研的jpaHelper.
jpaHelper的使用说明看这个页面: https://gitee.com/cym1102/jpaHelper 主要特点是不需要手动维护数据库结构, 添加model后自动生成表结构 jpaHelper的使用说明看这个页面: https://gitee.com/cym1102/jpaHelper 主要特点是不需要手动维护数据库结构, 添加model后自动生成表结构, 尽量不要写sql或xml文件, 使用ConditionAndWrapper ConditionOrWrapper进行sql构建和查询
网页框架用的jquery + layui官网说明: https://layui.dev/ 网页框架用的jquery + layui官网说明: https://layui.dev/
@@ -29,8 +29,8 @@ public class ExampleController extends BaseController {
ExampleService exampleService; ExampleService exampleService;
@RequestMapping("") @RequestMapping("")
public ModelAndView index(ModelAndView modelAndView, Page page) { public ModelAndView index(ModelAndView modelAndView, Page page, String keyword) {
page = exampleService.search(page); page = exampleService.search(page, keyword);
List<ExampleExt> exts = new ArrayList<ExampleExt>(); List<ExampleExt> exts = new ArrayList<ExampleExt>();
for (Example example : (List<Example>) page.getList()) { for (Example example : (List<Example>) page.getList()) {
@@ -46,6 +46,7 @@ public class ExampleController extends BaseController {
modelAndView.addObject("adminList", jpaHelper.findAll(Admin.class)); modelAndView.addObject("adminList", jpaHelper.findAll(Admin.class));
modelAndView.addObject("page", page); modelAndView.addObject("page", page);
modelAndView.addObject("keyword", keyword);
modelAndView.setViewName("/example/index"); modelAndView.setViewName("/example/index");
return modelAndView; return modelAndView;
} }
@@ -5,14 +5,22 @@ import org.springframework.stereotype.Service;
import com.cym.bean.Page; import com.cym.bean.Page;
import com.cym.model.Example; import com.cym.model.Example;
import com.cym.utils.ConditionAndWrapper;
import com.cym.utils.JpaHelper; import com.cym.utils.JpaHelper;
import cn.hutool.core.util.StrUtil;
@Service @Service
public class ExampleService { public class ExampleService {
@Autowired @Autowired
JpaHelper jpaHelper; JpaHelper jpaHelper;
public Page search(Page page) { public Page search(Page page, String keyword) {
ConditionAndWrapper conditionAndWrapper = new ConditionAndWrapper();
if (StrUtil.isNotEmpty(keyword)) {
conditionAndWrapper.like(Example::getName, keyword);
}
page = jpaHelper.findPageByQuery(page, Example.class); page = jpaHelper.findPageByQuery(page, Example.class);
return page; return page;
@@ -31,6 +31,19 @@
<div class="layui-inline"> <div class="layui-inline">
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="add()">添加模块</button> <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="add()">添加模块</button>
</div> </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="pageNum" value="${page.pageNum}">
<input type="hidden" name="pageSize" value="${page.pageSize}"> <input type="hidden" name="pageSize" value="${page.pageSize}">
</div> </div>