为项目添加一个搜索框,并改写JSP页面为HTML

本文详细介绍了如何实现站内商品搜索功能,并将其从JSP页面转换为HTML页面,包括表单构建、数据库查询及页面优化等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、搜索框完成站内搜索

实现功能思路:在首页文本框中输入任意字,点击搜索按钮将实现站内查询,将含有输入内容的商品显示在首页下方。

思路:

1.在项目首页中添加一个文本框和按钮

userBar

<form action="serch" th:object="${goodsFrom}" method="post">
         <li>
		<span><input name="commodityName" type="text" /></span>
		<span><button type="submit" name="sousuo">搜索</button></span> 
	</li>		
          </form>

2.在GoodsController中定义一个方法将存放在bean中的值取到result中传给list输出到首页。

在这里进行了购物车的实例化


GoodsController

@RequestMapping(value = "/serch", method = RequestMethod.POST)
	public String delete(GoodsForm goodsForm, Model model) {
		List<GoodsForm> rescult = goodsService.serchGoodsList(goodsForm);
		model.addAttribute("list", rescult);
		CartForm cartForm = new CartForm();
		model.addAttribute("cartList", cartService.searchCartList(cartForm));
		return "shop/index";
	}

3.定义一个list的方法存放搜索出来的结果列表

GoodsService

public  List<GoodsForm> serchGoodsList(GoodsForm frm) {

	List<GoodsForm> result = queryDao.executeForObjectList("Goods.selectList", frm);
			return result;
		}

4.要完成站内的搜索,就必须在数据库中筛选出含有输入内容的数据。则此时就必须注意,一个完整的项目都是各个表之间的相互调用,此时查询关联表的情况下,表名为多个。而模糊查询输入的内容对应的SQL文为:

where name like %XX%

而今天项目中的是    where  表名.name   like   '%$ XXXXXX $%'      而且where中多个条件并存时用AND或者OR连接

GoodsSqlMap

<select id="selectList"
		parameterClass="cn.agriculture.web.form.GoodsForm"
		resultClass="cn.agriculture.web.form.GoodsForm">
			SELECT commodity.commodity_id as commodityId,
			commodity.type as type,
			supplier.supplier_name as supplierName,
			brand.brand_name as brandName,
			commodity.commodity_name as commodityName,
			commodity.weight as weight,
			commodity.is_gift as isGift,
			commodity.specifications as specifications,
			commodity.unit as unit,
			commodity.benchmark_price as benchmarkPrice,
			commodity.guide_price as guidePrice,
			commodity.retail_price as retailPrice,
			commodity.competition_level as competitionLevel,
			commodity.note as note,
			commodity.update_time as updateTime,
			commodity.update_user as updateUser,
			commodity.picture_id as pictureId,
			stock.stock as stock
		FROM commodity, supplier, brand, stock
		WHERE commodity.commodity_id = stock.commodity_id
		AND commodity.supplier_id = supplier.supplier_id
		AND commodity.brand_id = brand.brand_id
		AND commodity.commodity_name like '%$commodityName$%'
	
	</select>

二、改JSP为HTML页面

思路:将JSP页面改为HTML是方便前台后期的修改,需要将JSP页面中的所有标签换成HTML中的表达方式

form表单中需要添加一项   th:value="${userBean} " 表示引用的是UserBean 中的数据

文本输出要用   th:text="${MESSAGE}"

<a th:href="@{delete(userId=${user.userId})}"   其中@为指令,userId=${user.userId}为取值操作

转载于:https://my.oschina.net/u/2411768/blog/482346

<think>好的,我现在需要帮用户把包含el-steps和v-if的Vue代码转换成JSP。首先,我得仔细看看用户提供的Vue代码。原来的代码用了Vue的指令,比如v-if和v-for,还有Element UI的组件el-steps和el-step。用户的目标是转成JSP,也就是用Java服务器端的标签和HTML结合的方式来实现类似效果。 首先,处理v-if指令。在Vue里,v-if会根据条件渲染或销毁元素。JSP中没有直接的等价物,但可以用JSTL的<c:if>标签。比如,原来的<div v-if="procedureList && procedureList.length>0">可以转换成<c:if test="${not empty procedureList}">。这里需要注意,JSP中的条件判断需要依赖后端传递的数据,所以用户需要确保procedureList在请求属性中可用。 接下来是v-for循环。Vue里用v-for来遍历数组,生成多个元素。JSP中可以使用JSTL的<c:forEach>标签。例如,<el-step v-for="item in procedureList">需要转换为<c:forEach items="${procedureList}" var="item">。每个循环项中的内容需要替换成静态的HTML结构,同时引用item的属性,比如${item.title}。 然后是处理Element UI的组件。el-steps和el-step是第三方组件,转换成JSP时需要手动实现它们的结构和样式。可能需要查阅Element UI的文档,了解这些组件生成的HTML结构和对应的CSS类。比如,el-steps可能有对应的CSS类名,如el-steps和el-step,需要确保这些样式被正确引入到JSP页面中,否则样式会丢失。 用户提供的代码中有动态绑定的属性,比如:active="100",这在Vue中是动态属性绑定。在JSP中,可以直接使用EL表达式,例如,替换成active="${activeStep}",但需要后端传递activeStep的值。不过原示例中的active是固定值100,可能需要确认是否需要动态设置,还是直接写死。 另外,原代码中有一些内联样式,比如padding-left和padding-top,这些可以直接保留在HTML中。但是Vue中的响应式数据绑定,如{{item.deadline}},需要转换成JSP的EL表达式,如${item.deadline},确保数据从后端正确传递。 关于步骤条的结构,el-steps在Element UI中可能生成一系列的步骤项,每个步骤包含标题和描述。在JSP中,需要用HTML结构模拟,比如用div包裹每个步骤,添加对应的类名和样式。可能需要引入Element UI的CSS文件,或者手动编写样式来匹配原来的外观。 还有,原Vue代码中的插槽(slot)比如<template slot="title">需要转换成JSP中的相应结构。可能需要将插槽内容直接写入对应的HTML元素中,比如在步骤的标题部分直接放置标题内容。 最后,需要考虑JSP中是否使用Ajax来动态加载数据。原Vue代码可能通过Vue实例动态获取数据,而JSP通常是在服务器端渲染数据,所以需要确保数据在渲染时已经由后端处理传入JSP页面。 总结下来,转换的步骤包括:替换Vue指令为JSTL标签,转换Element UI组件为HTML结构,引入必要的CSS和JavaScript文件,确保数据通过EL表达式正确显示。同时,需要注意样式的保持和动态功能的实现可能受限,需要依赖后端的数据处理和前端的静态结构。</think>根据最新引用[1]中提到的CSS3特性与JSP实现需求,以下是Vue到JSP的完整转换方案: ### 一、核心转换步骤 #### 1. **条件渲染(v-if → JSTL)** ```jsp <c:if test="${not empty procedureList}"> <div class="el-steps stepStyle" style="position: relative"> <c:forEach items="${procedureList}" var="item"> <div class="el-step"> <div class="el-step__title">${item.title}</div> <div style="margin-top: 15px">${item.content}</div> </div> </c:forEach> </div> </c:if> <c:if test="${empty procedureList}"> <div style="color: #72767b; text-align:center"> 暂无办理流程 </div> </c:if> ``` #### 2. **步骤条样式实现(参考引用[1]的CSS技巧)** ```jsp <style> .el-steps { transition: visibility 0.3s; /* 应用引用[1]的visibility过渡特性 */ } .el-step__title::after { content: ""; display: inline-block; width: 20px; height: 20px; background: url('data:image/svg+xml;utf8,<svg ...></svg>'); /* 使用SVG替代Element UI图标 */ } </style> ``` ### 三、完整转换代码 ```jsp <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <div style="padding-left: 20px; padding-top:30px; min-height: 70vh"> <c:choose> <c:when test="${not empty procedureList}"> <div class="el-steps stepStyle" style="position: relative"> <c:forEach items="${procedureList}" var="item" varStatus="loop"> <div class="el-step"> <div class="el-step__head ${loop.index < 100 ? 'is-process' : 'is-wait'}"> <div class="el-step__line"></div> <div class="el-step__icon">${loop.index + 1}</div> </div> <div class="el-step__main"> <div class="el-step__title">${item.title}</div> <div class="el-step__description"> <div style="margin-top: 15px">${item.content}</div> <div style="background-color: #eef1f6; padding: 8px"> 要求:<br>${item.re_question} </div> </div> </div> </div> </c:forEach> </div> </c:when> <c:otherwise> <div style="color: #72767b; text-align:center; margin-top: 100px"> 暂无办理流程 </div> </c:otherwise> </c:choose> </div> ``` ### 四、关键差异处理 | Vue特性 | JSP实现方案 | |---------------|-----------------------------------------------------------------------------| | `v-if` | JSTL `<c:if>` + `<c:choose>` | | `v-for` | JSTL `<c:forEach>` | | 组件样式 | 手动实现CSS(参考引用[1]的visibility过渡) | | 动态属性绑定 | EL表达式 `${}` | | 插槽机制 | JSP自定义标签(需配合编写taglib) | ### 五、注意事项 1. **数据准备**:需在Servlet中设置`request.setAttribute("procedureList", dataList)` 2. **样式兼容**:需手动引入Element UI的CSS文件或实现等效样式(引用[1]提到的transition需特别注意) 3. **交互功能**:原Vue的点击事件需转换为传统JS事件绑定 ```jsp <button onclick="handleClick(${item.id})">操作</button> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值