赞
踩
完成该功能的前提是配置好Solr服务器,这一部分内容可以参考博主上一篇的内容:基于Lucene的全文搜索服务器solr
1.如果不想配置solr服务器,直接百度网盘下载,然后解压solr压缩包至D盘,就可以使用了
链接:https://pan.baidu.com/s/15M9lnfqvR0p0v81STlQ6Mg
提取码:cnai
2.建立如下工程目录结构
3.在pom.xml中导入pom依赖
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <spring.version>5.0.2.RELEASE</spring.version> <github.pagehelper.version>5.1.10</github.pagehelper.version> </properties> <dependencies> <!--spring核心依赖--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <!--springaop--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.2.4.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <!--aspectj--> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.8</version> </dependency> <!--springmvc依赖--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!--mybatis依赖--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.11</version> </dependency> <!--数据库连接池--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.21</version> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>compile</scope> </dependency> <!--jstl表达式支持--> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!--Jackson--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.8</version> </dependency> <!--solrj依赖--> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>7.1.0</version> </dependency> </dependencies>
4.在resources资源文件中创建spring_solr
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--spring整合solr-->
<bean id="httpSolrClient" class="org.apache.solr.client.solrj.impl.HttpSolrClient">
<constructor-arg name="builder" value="http://localhost:8081/solr/demo_core/"></constructor-arg>
</bean>
</beans>
5.在resources资源文件中创建jdbc.properties
jdbc_url=jdbc:mysql://localhost:3306/solr
jdbc_driver=com.mysql.jdbc.Driver
jdbc_user=root
jdbc_password=123
6.在resources资源文件中创建spring_core
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--Spring IOC指定扫描的包@Service..@Repository @Component...--> <context:component-scan base-package="com.bianyiit"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!--引入外部资源classpath:jdbc.properties--> <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder> <!--配置数据源driverClassName--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="url" value="${jdbc_url}"></property> <property name="driverClassName" value="${jdbc_driver}"></property> <property name="username" value="${jdbc_user}"></property> <property name="password" value="${jdbc_password}"></property> <!--配置初始化大小,最小连接数和最大连接数--> <property name="initialSize" value="1"></property> <property name="minIdle" value="1"></property> <property name="maxActive" value="10"></property> <!--配置最大连接时间--> <property name="maxWait" value="10000"></property> <!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒--> <property name="timeBetweenEvictionRunsMillis" value="60000"></property> <!--配置一个连接在池中最小生存的时间,单位是毫秒--> <property name="minEvictableIdleTimeMillis" value="300000"></property> <!--这里配置提交方式,默认就是TRUE,可以不用配置--> <property name="defaultAutoCommit" value="true" /> <!--配置监控统计拦截的filters--> <property name="filters" value="stat" /> </bean> <!--spring与mybatis的整合--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!--注入数据源--> <property name="dataSource" ref="dataSource"></property> <!--配置分页插件--> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> helperDialect=mysql </value> </property> </bean> </array> </property> <!--扫描mybatis映射文件--> <!--<property name="mapperLocations" value="value="classpath:mapper/*.xml""></property>--> <!--引入外部的 mybatis.xml配置--> <!--<property name="configLocation" value="classpath:mybatis.xml"></property>--> </bean> <!--根据sqlsessionFactoryBean得到sqlsession--> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg> </bean> <!--配置MapperScannerConfigurer自动扫描 将Mapper接口生成代理注入到Spring DAO接口所在包名,Spring会自动查找其下的类--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.bianyiit.dao"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <!--配置声明式事务管理--> <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--开启声明式事务管理注解支持:注意这里导入的是tx的那一个driven--> <tx:annotation-driven transaction-manager="dataSourceTransactionManager"></tx:annotation-driven> </beans>
7.在resources资源文件中创建spring_mvc
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--开启对Controller的包扫描--> <context:component-scan base-package="com.bianyiit.web"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 处理静态资源 将在 SpringMVC 上下文中定义一个 DefaultServletHttpRequestHandler, 它会对进入 DispatcherServlet 的 请求进行筛查, 如果发现是没有经过映射的请求,就将该请求交由 WEB 应用服务器默认的 Servlet 处理, 如果不是静态资源的请求,才由 DispatcherServlet 继续处理--> <mvc:default-servlet-handler /> <!-- 开启对SpringMVC注解的支持 --> <mvc:annotation-driven></mvc:annotation-driven> </beans>
8.找到webapp/WEB-INF目录下的web.xml,配置监听器,编码过滤器,前端控制器
注意:web-app标签中需要引入约束,这些约束我们在创建web项目时是没有的,切记这里一定要加上约束,不然css,js,image资源会被拦截掉
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring_*.xml</param-value> </context-param> <!--配置编码过滤器--> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <!--配置过滤器HiddenHttpMethodFilter,可以将DELETE、PUT等这些请求转换为标准的 http 方法,使得支持 GET、POST、PUT 与 DELETE 请求。--> <filter> <filter-name>hiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--配置监听器--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--配置前端控制器--> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <!-- 服务器启动的时候,让DispatcherServlet对象创建 --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <!-- / 拦截所有的请求,不包括JSP。 /* 拦截所有的请求(包括JSP) --> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
9.在webapp目录下创建css、js、resource包将下述网盘下的资源拷入其中
链接:https://pan.baidu.com/s/1EsTHQ7j8CCILTMoogA9TRQ
提取码:btl7
10.在webapp目录下创建index.jsp界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta content="utf-8" http-equiv="charset"> <link rel="stylesheet" type="text/css" href="css/base.css" media="all"> <link rel="stylesheet" type="text/css" href="css/plist20131112.css" media="all"> <link rel="stylesheet" type="text/css" href="css/list-page-20141009.css" media="all"> <link rel="stylesheet" type="text/css" href="css/pop_compare.css" media="all"> <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script> <style id="style-1-cropbar-clipper">/* Copyright 2014 Evernote Corporation. All rights reserved. */ .en-markup-crop-options { top: 18px !important; left: 50% !important; margin-left: -100px !important; width: 200px !important; border: 2px rgba(255,255,255,.38) solid !important; border-radius: 4px !important; } .en-markup-crop-options div div:first-of-type { margin-left: 0px !important; } </style> <script type="text/javascript"> function query() { //执行关键词查询时清空过滤条件 document.getElementById("catalog_name").value=""; document.getElementById("price").value=""; document.getElementById("page").value=""; //执行查询 queryList(); } function queryList() { //提交表单 document.getElementById("actionForm").submit(); } function filter(key, value) { document.getElementById(key).value=value; queryList(); } function sort() { var s = document.getElementById("sort").value; if (s != "1") { s = "1"; } else { s = "0"; } document.getElementById("sort").value = s; queryList(); } function changePage(p) { var curpage = Number(document.getElementById("page").value); curpage = curpage + p; document.getElementById("page").value = curpage; queryList(); } </script> </head> <body class="root61"> <div id="shortcut-2013"> <div class="w"> <ul class="fl lh"> <li class="fore1 ld"><b></b><a href="#" rel="nofollow">收藏京东</a></li> </ul> <ul class="fr lh"> <li class="fore1" id="loginbar">您好,欢迎来到京东!<span><a href="#">[登录]</a> <a href="#" class="link-regist">[免费注册]</a></span></li> <li class="fore2 ld"> <s></s> <a href="#" rel="nofollow">我的订单</a> </li> <li class="fore2-1 ld" id="jd-vip"><i></i> <i></i> <s></s> <a target="_blank" rel="nofollow" href="http://vip.jd.com/">会员俱乐部</a> </li> <li class="fore2-2 ld" id="jd-dakehu"> <i></i><s></s> <a href="http://b.jd.com/" target="_blank" rel="nofollow">企业频道</a> </li> <li class="fore3 ld menu" id="app-jd" data-widget="dropdown" clstag="homepage|keycount|home2013|01d"><s></s> <i></i> <span class="outline"></span> <span class="blank"></span> <a href="http://app.jd.com/" target="_blank">手机京东</a> <b></b> </li> <li class="fore4 ld menu" id="biz-service" data-widget="dropdown"> <s></s> <span class="outline"></span> <span class="blank"></span> 客户服务 <b></b> </li> <li class="fore5 ld menu" id="site-nav" data-widget="dropdown"> <s></s> <span class="outline"></span> <span class="blank"></span> 网站导航 <b></b> </li> </ul> <span class="clr"></span> </div> </div><!--shortcut end--> <div id="o-header-2013"> <div class="w" id="header-2013"> <div id="logo-2013" class="ld"><a href="http://www.jd.com/" hidefocus="true"><b></b><img src="resource/logo-201305.png" width="270" height="60" alt="京东"></a></div> <!--logo end--> <div id="search-2013"> <div class="i-search ld"> <ul id="shelper" class="hide"></ul> <form id="actionForm" action="product/get" method="POST"> <div class="form"> <input type="text" class="text" accesskey="s" name="queryString" id="key" value="${queryString}" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) {query()}"> <input type="button" value="搜索" class="button" onclick="query()"> </div> <input type="hidden" name="catalog_name" id="catalog_name" value="${catalog_name }"/> <input type="hidden" name="price" id="price" value="${price}"/> <input type="hidden" name="page" id="page" value="${curPage }"/> <input type="hidden" name="sort" id="sort" value="${sort }"/> </form> </div> <div id="hotwords"></div> </div> <!--search end--> <div id="my360buy-2013"> <dl> <dt class="ld"><s></s><a href="http://home.jd.com/">我的京东</a><b></b></dt> <dd> <div class="loading-style1"><b></b>加载中,请稍候...</div> </dd> </dl> </div> <!--my360buy end--> <div id="settleup-2013"> <dl> <dt class="ld"><s></s><span class="shopping"><span id="shopping-amount">0</span></span><a href="http://cart.jd.com/cart/cart.html" id="settleup-url">去购物车结算</a> <b></b> </dt> <dd> <div class="prompt"> <div class="loading-style1"><b></b>加载中,请稍候...</div> </div> </dd> </dl> </div> <!--settleup end--> </div> <!--header end--> <div class="w"> <div id="nav-2013"> <div id="categorys-2013" class="categorys-2014"> <div class="mt ld"> <h2><a href="http://www.jd.com/allSort.aspx">全部商品分类<b></b></a></h2> </div> </div> <div id="treasure"></div> <ul id="navitems-2013"> <li class="fore1" id="nav-home"><a href="http://www.jd.com/">首页</a></li> <li class="fore2" id="nav-fashion"><a href="http://fashion.jd.com/">服装城</a></li> <li class="fore3" id="nav-chaoshi"><a href="http://channel.jd.com/chaoshi.html">食品</a></li> <li class="fore4" id="nav-tuan"><a href="http://tuan.jd.com/" target="_blank">团购</a></li> <li class="fore5" id="nav-auction"><a href="http://auction.jd.com/">夺宝岛</a></li> <li class="fore6" id="nav-shan"><a href="http://red.jd.com/">闪购</a></li> <li class="fore7" id="nav-jinrong"><a href="http://jr.jd.com/" target="_blank">金融</a></li> </ul> </div> </div> </div> <div class="w"> <div class="breadcrumb"> <strong><a href="#">服饰内衣</a></strong><span> > <a href="#">女装</a> > <a href="#">T恤</a></span> </div> </div> <div class="w main"> <div class="right-extra"> <div id="select" clstag="thirdtype|keycount|thirdtype|select" class="m"> <div class="mt"> <h1> T恤 -<strong> 商品筛选</strong> </h1> </div> <div class="mc attrs"> <div data-id="100001" class="brand-attr"> <div class="attr"> <div class="a-key">商品类别:</div> <div class="a-values"> <div class="v-tabs"> <div class="tabcon"> <div> <a href="javascript:filter('catalog_name', '幽默杂货')" >幽默杂货</a> </div> <div> <a href="javascript:filter('catalog_name', '时尚卫浴')">时尚卫浴</a> </div> <div> <a href="javascript:filter('catalog_name', '另类文体')">另类文体</a> </div> <div> <a href="javascript:filter('catalog_name', '创意相架')">创意相架</a> </div> <div> <a href="javascript:filter('catalog_name', '巧妙收纳')">巧妙收纳</a> </div> <div> <a href="javascript:filter('catalog_name', '与钟不同')">与钟不同</a> </div> <div> <a href="javascript:filter('catalog_name', '个性男人')">个性男人</a> </div> <div> <a href="javascript:filter('catalog_name', '电脑周边')">电脑周边</a> </div> <div> <a href="javascript:filter('catalog_name', '品质家电')">品质家电</a> </div> <div> <a href="javascript:filter('catalog_name', '品味茶杯')">品味茶杯</a> </div> <div> <a href="javascript:filter('catalog_name', '四季用品')">四季用品</a> </div> <div> <a href="javascript:filter('catalog_name', '健康宝宝')">健康宝宝</a> </div> <div> <a href="javascript:filter('catalog_name', '新潮美容')">新潮美容</a> </div> <div> <a href="javascript:filter('catalog_name', '产品配件')">产品配件</a> </div> <div> <a href="javascript:filter('catalog_name', '雅致灯饰')">雅致灯饰</a> </div> <div> <a href="javascript:filter('catalog_name', '阳光车饰')">阳光车饰</a> </div> <div> <a href="javascript:filter('catalog_name', '趣味纸抽')">趣味纸抽</a> </div> <div> <a href="javascript:filter('catalog_name', '布艺毛绒')">布艺毛绒</a> </div> <div> <a href="javascript:filter('catalog_name', '益智手工')">益智手工</a> </div> <div> <a href="javascript:filter('catalog_name', '环保餐具')">环保餐具</a> </div> <div> <a href="javascript:filter('catalog_name', '闪亮匙扣')">闪亮匙扣</a> </div> <div> <a href="javascript:filter('catalog_name', '手机饰品')">手机饰品</a> </div> <div> <a href="javascript:filter('catalog_name', '精品数码')">精品数码</a> </div> <div> <a href="javascript:filter('catalog_name', '理财钱罐')">理财钱罐</a> </div> <div> <a href="javascript:filter('catalog_name', '美味厨房')">美味厨房</a> </div> <div> <a href="javascript:filter('catalog_name', '保健按摩')">保健按摩</a> </div> <div> <a href="javascript:filter('catalog_name', '魅力女人')">魅力女人</a> </div> </div> </div> </div> </div> </div> <div data-id="100002" class="prop-attrs"> <div class="attr"> <div class="a-key">价格:</div> <div class="a-values"> <div class="v-fold"> <ul class="f-list"> <li><a href="javascript:filter('price','0-9')">0-9</a></li> <li><a href="javascript:filter('price','10-19')">10-19</a></li> <li><a href="javascript:filter('price','20-29')">20-29</a></li> <li><a href="javascript:filter('price','30-39')">30-39</a></li> <li><a href="javascript:filter('price','40-49')">40-49</a></li> <li><a href="javascript:filter('price','50-*')">50以上</a></li> </ul> </div> </div> </div> </div> </div> </div> <div id="filter"> <div class="cls"></div> <div class="fore1"> <dl class="order"> <dt>排序:</dt> <dd> <a href="javascript:sort()">价格</a><b></b> </dd> </dl> <dl class="activity"> <dd></dd> </dl> <div class="pagin pagin-m"> <span class="text"><i>当前1页</i>/共10页</span> <a href="javascript:changePage(-1)" class="prev">上一页<b></b></a> <a href="javascript:changePage(1)" class="next">下一页<b></b></a> </div> <div class="total"> <span>共<strong>108</strong>个商品 </span> </div> <span class="clr"></span> </div> </div> <!--商品列表开始--> <div id="plist" class="m plist-n7 plist-n8 prebuy"> <ul class="list-h"> <c:forEach var="p" items="${listProduct}"> <li pid="${p.pid }"> <div class="lh-wrap"> <div class="p-img"> <a target="_blank" href="#"> <img width="220" height="282" class="err-product" src="images/${p.picture}"> </a> </div> <div class="p-name"> <a target="_blank" href="#">${p.pname }</a> </div> <div class="p-price"> <strong>¥<fmt:formatNumber value="${p.price}" maxFractionDigits="2"/></strong><span id="p1269191543"></span> </div> </div> </li> </c:forEach> </ul> </div> <!--商品列表结束--> </div> <div class="left"> <div id="sortlist" clstag="thirdtype|keycount|thirdtype|sortlist" class="m"> <div class="mt"> <h2>服饰内衣</h2> </div> <div class="mc"> <div class="item current"> <h3> <b></b>女装 </h3> <ul> <li><a href="http://list.jd.com/1315-1343-1355.html">T恤</a></li> <li><a href="http://list.jd.com/1315-1343-1354.html">衬衫</a></li> <li><a href="http://list.jd.com/1315-1343-1356.html">针织衫</a></li> <li><a href="http://list.jd.com/1315-1343-9713.html">雪纺衫</a></li> <li><a href="http://list.jd.com/1315-1343-9710.html">卫衣</a></li> <li><a href="http://list.jd.com/1315-1343-9714.html">马甲</a></li> <li><a href="http://list.jd.com/1315-1343-9719.html">连衣裙</a></li> <li><a href="http://list.jd.com/1315-1343-9720.html">半身裙</a></li> <li><a href="http://list.jd.com/1315-1343-9715.html">牛仔裤</a></li> <li><a href="http://list.jd.com/1315-1343-9717.html">休闲裤</a></li> <li><a href="http://list.jd.com/1315-1343-9716.html">打底裤</a></li> <li><a href="http://list.jd.com/1315-1343-9718.html">正装裤</a></li> <li><a href="http://list.jd.com/1315-1343-9711.html">小西装</a></li> <li><a href="http://list.jd.com/1315-1343-9712.html">短外套</a></li> <li><a href="http://list.jd.com/1315-1343-9708.html">风衣</a></li> <li><a href="http://list.jd.com/1315-1343-9706.html">毛呢大衣</a></li> <li><a href="http://list.jd.com/1315-1343-9707.html">真皮皮衣</a></li> <li><a href="http://list.jd.com/1315-1343-9705.html">棉服</a></li> <li><a href="http://list.jd.com/1315-1343-3983.html">羽绒服</a></li> <li><a href="http://list.jd.com/1315-1343-9722.html">大码女装</a></li> <li><a href="http://list.jd.com/1315-1343-9721.html">中老年女装</a></li> <li><a href="http://list.jd.com/1315-1343-9723.html">婚纱</a></li> <li><a href="http://list.jd.com/1315-1343-11985.html">打底衫</a></li> <li><a href="http://list.jd.com/1315-1343-11986.html">旗袍/唐装</a></li> <li><a href="http://list.jd.com/1315-1343-11987.html">加绒裤</a></li> <li><a href="http://list.jd.com/1315-1343-11988.html">吊带/背心</a></li> <li><a href="http://list.jd.com/1315-1343-11989.html">羊绒衫</a></li> <li><a href="http://list.jd.com/1315-1343-11991.html">短裤</a></li> <li><a href="http://list.jd.com/1315-1343-11993.html">皮草</a></li> <li><a href="http://list.jd.com/1315-1343-11996.html">礼服</a></li> <li><a href="http://list.jd.com/1315-1343-11998.html">仿皮皮衣</a></li> <li><a href="http://list.jd.com/1315-1343-11999.html">羊毛衫</a></li> <li><a href="http://list.jd.com/1315-1343-12000.html">设计师/潮牌</a></li> </ul> </div> <div class="item"> <h3> <b></b>男装 </h3> </div> <div class="item"> <h3> <b></b>内衣 </h3> </div> <div class="item"> <h3> <b></b>服饰配件 </h3> </div> </div> </div> <div id="limitBuy"> <div id="limitbuy9199" clstag="thirdtype|keycount|thirdtype|limitbuy536" class="m limitbuy hide"> <div class="mt"> <h2>服饰鞋帽</h2> </div> <div class="mc"> <div id="clock9199" class="clock">正在加载…</div> <div id="limit9199"></div> </div> </div> </div> <div id="ad_left" reco_id="6" class="m m0 hide"></div> <!--用户最终购买--> <div id="finalbuy" class="hide m m0" style="display: block;"> <div class="mt"> <h2> 浏览<font color="red">T恤</font>最终购买 </h2> </div> <div class="mc"> </div> </div> <div id="weekRank" clstag="thirdtype|keycount|thirdtype|mrank" class="m rank"> <div class="mt"> <h2>一周销量排行</h2> </div> <div class="mc"> </div> </div> </div><!--<div class="left">--> <span class="clr"></span> <div id="Collect_Tip" class="Tip360 w260"></div> </div><!--<div class="w main">--> <div class="w"> <div id="service-2013"> <dl class="fore1"> <dt><b></b><strong>购物指南</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-56.html" target="_blank" rel="nofollow">购物流程</a></div> <div><a href="http://help.jd.com/help/question-57.html" target="_blank" rel="nofollow">会员介绍</a></div> <div><a href="http://help.jd.com/help/question-181.html" target="_blank" rel="nofollow">团购/机票</a></div> <div><a href="http://help.jd.com/help/question-61.html" target="_blank" rel="nofollow">常见问题</a></div> <div><a href="http://help.jd.com/help/question-63.html" target="_blank" rel="nofollow">大家电</a></div> <div><a href="http://help.jd.com/index.html" target="_blank" rel="nofollow">联系客服</a></div> </dd> </dl> <dl class="fore2"> <dt><b></b><strong>配送方式</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-64.html" target="_blank" rel="nofollow">上门自提</a></div> <div><a href="http://help.jd.com/help/question-360.html" target="_blank" rel="nofollow">211限时达</a></div> <div><a href="http://help.jd.com/help/distribution-768.html" target="_blank" rel="nofollow">配送服务查询</a></div> <div><a href="http://help.jd.com/help/question-892.html#help2215" target="_blank" rel="nofollow">配送费收取标准</a></div> <div><a href="http://en.jd.com/chinese.html" target="_blank">海外配送</a></div> </dd> </dl> <dl class="fore3"> <dt><b></b><strong>支付方式</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-67.html" target="_blank" rel="nofollow">货到付款</a></div> <div><a href="http://help.jd.com/help/question-68.html" target="_blank" rel="nofollow">在线支付</a></div> <div><a href="http://help.jd.com/help/question-71.html" target="_blank" rel="nofollow">分期付款</a></div> <div><a href="http://help.jd.com/help/question-69.html" target="_blank" rel="nofollow">邮局汇款</a></div> <div><a href="http://help.jd.com/help/question-70.html" target="_blank" rel="nofollow">公司转账</a></div> </dd> </dl> <dl class="fore4"> <dt><b></b><strong>售后服务</strong></dt> <dd> <div><a href="http://myjd.jd.com/afs/help/afshelp.action" target="_blank" rel="nofollow">售后政策</a></div> <div><a href="http://help.jd.com/help/question-99.html" target="_blank" rel="nofollow">价格保护</a></div> <div><a href="http://help.jd.com/help/question-100.html" target="_blank" rel="nofollow">退款说明</a></div> <div><a href="http://myjd.jd.com/repair/repairs.action" target="_blank" rel="nofollow">返修/退换货</a></div> <div><a href="http://help.jd.com/help/question-881.html" target="_blank" rel="nofollow">取消订单</a></div> </dd> </dl> <dl class="fore5"> <dt><b></b><strong>特色服务</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-79.html" target="_blank">夺宝岛</a></div> <div><a href="http://help.jd.com/help/question-86.html" target="_blank">DIY装机</a></div> <div><a href="http://fuwu.jd.com/" target="_blank" rel="nofollow">延保服务</a></div> <div><a href="http://giftcard.jd.com/market/index.action" target="_blank" rel="nofollow">京东E卡</a></div> <div><a href="http://help.jd.com/help/question-91.html" target="_blank" rel="nofollow">节能补贴</a></div> <div><a href="http://mobile.jd.com/" target="_blank" rel="nofollow">京东通信</a></div> </dd> </dl> <span class="clr"></span> </div> </div><!-- service end --><div class="w"> <div id="footer-2013"> <div class="links"> <a rel="nofollow" target="_blank" href="http://www.jd.com/intro/about.aspx">关于我们</a>|<a rel="nofollow" target="_blank" href="http://www.jd.com/contact/">联系我们</a>|<a rel="nofollow" target="_blank" href="http://zhaopin.jd.com/">人才招聘</a>|<a rel="nofollow" target="_blank" href="http://www.jd.com/contact/joinin.aspx">商家入驻</a>|<a rel="nofollow" target="_blank" href="http://sale.jd.com/act/y3surX7qpM.html">广告服务</a>|<a rel="nofollow" target="_blank" href="http://app.jd.com/">手机京东</a>|<a target="_blank" href="http://club.jd.com/links.aspx">友情链接</a>|<a target="_blank" href="http://cps.jd.com/">销售联盟</a>|<a href="http://club.jd.com/" target="_blank">京东社区</a>|<a href="http://gongyi.jd.com/" target="_blank">京东公益</a></div> <div class="copyright">北京市公安局朝阳分局备案编号110105014669 | 京ICP证070359号 | 互联网药品信息服务资格证编号(京)-非经营性-2011-0034<br><a rel="nofollow" href="http://misc.360buyimg.com/skin/df/i/com/f_music.jpg" target="_blank">音像制品经营许可证苏宿批005号</a>| 出版物经营许可证编号新出发(苏)批字第N-012号 | 互联网出版许可证编号新出网证(京)字150号<br><a href="http://misc.360buyimg.com/wz/wlwhjyxkz.jpg" target="_blank">网络文化经营许可证京网文[2011]0168-061号</a>Copyright © 2004-2015 京东JD.com 版权所有<br>京东旗下网站:<a href="http://en.jd.com/" target="_blank">English Site</a></div> <div class="authentication"><a rel="nofollow" target="_blank" href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202007080200026"><img width="108" height="40" alt="经营性网站备案中心" src="<c:url value='/resource'/>/108_40_zZOKnl.gif" class="err-product"></a> <a rel="nofollow" target="_blank" tabindex="-1" href="https://ss.cnnic.cn/verifyseal.dll?sn=2008070300100000031&ct=df&pa=294005" id="urlknet"><img width="108" height="40" border="true" name="CNNIC_seal" alt="可信网站" src="<c:url value='/resource'/>/kxwz.gif" class="err-product"></a> <a rel="nofollow" target="_blank" href="http://www.bj.cyberpolice.cn/index.do"><img width="108" height="40" alt="朝阳网络警察" src="<c:url value='/resource'/>/cywljc.png" class="err-product"></a> <a rel="nofollow" target="_blank" href="https://search.szfw.org/cert/l/CX20120111001803001836"><img width="112" height="40" src="<c:url value='/resource'/>/112_40_WvArIl.png" class="err-product"></a> </div> </div> </div> </body> </html>
11.在webapp目录下创建jd.jsp界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta content="utf-8" http-equiv="charset"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/base.css" media="all"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/plist20131112.css" media="all"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/list-page-20141009.css" media="all"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/pop_compare.css" media="all"> <link rel="shortcut icon" type="image/ico" href="http://list.jd.com/favicon.ico"> <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.2.6.pack.js"></script> <style id="style-1-cropbar-clipper">/* Copyright 2014 Evernote Corporation. All rights reserved. */ .en-markup-crop-options { top: 18px !important; left: 50% !important; margin-left: -100px !important; width: 200px !important; border: 2px rgba(255,255,255,.38) solid !important; border-radius: 4px !important; } .en-markup-crop-options div div:first-of-type { margin-left: 0px !important; } </style> <script type="text/javascript"> function query() { //执行关键词查询时清空过滤条件 document.getElementById("catalog_name").value=""; document.getElementById("price").value=""; document.getElementById("page").value=""; //执行查询 queryList(); } function queryList() { //提交表单 document.getElementById("actionForm").submit(); } function filter(key, value) { document.getElementById(key).value=value; queryList(); } function sort() { var s = document.getElementById("sort").value; if (s != "1") { s = "1"; } else { s = "0"; } document.getElementById("sort").value = s; queryList(); } function changePage(p) { var curpage = Number(document.getElementById("page").value); curpage = curpage + p; document.getElementById("page").value = curpage; queryList(); } </script> </head> <body class="root61"> <div id="shortcut-2013"> <div class="w"> <ul class="fl lh"> <li class="fore1 ld"><b></b><a href="#" rel="nofollow">收藏京东</a></li> </ul> <ul class="fr lh"> <li class="fore1" id="loginbar">您好,欢迎来到京东!<span><a href="#">[登录]</a> <a href="#" class="link-regist">[免费注册]</a></span></li> <li class="fore2 ld"> <s></s> <a href="#" rel="nofollow">我的订单</a> </li> <li class="fore2-1 ld" id="jd-vip"><i></i> <i></i> <s></s> <a target="_blank" rel="nofollow" href="http://vip.jd.com/">会员俱乐部</a> </li> <li class="fore2-2 ld" id="jd-dakehu"> <i></i><s></s> <a href="http://b.jd.com/" target="_blank" rel="nofollow">企业频道</a> </li> <li class="fore3 ld menu" id="app-jd" data-widget="dropdown" clstag="homepage|keycount|home2013|01d"><s></s> <i></i> <span class="outline"></span> <span class="blank"></span> <a href="http://app.jd.com/" target="_blank">手机京东</a> <b></b> </li> <li class="fore4 ld menu" id="biz-service" data-widget="dropdown"> <s></s> <span class="outline"></span> <span class="blank"></span> 客户服务 <b></b> </li> <li class="fore5 ld menu" id="site-nav" data-widget="dropdown"> <s></s> <span class="outline"></span> <span class="blank"></span> 网站导航 <b></b> </li> </ul> <span class="clr"></span> </div> </div><!--shortcut end--> <div id="o-header-2013"> <div class="w" id="header-2013"> <div id="logo-2013" class="ld"><a href="http://www.jd.com/" hidefocus="true"><b></b><img src="${pageContext.request.contextPath}/resource/logo-201305.png" width="270" height="60" alt="京东"></a></div> <!--logo end--> <div id="search-2013"> <div class="i-search ld"> <ul id="shelper" class="hide"></ul> <form id="actionForm" action="/product/get" method="GET"> <div class="form"> <input type="text" class="text" accesskey="s" name="keyword" id="key" value="${keyword}" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) {query()}"> <input type="button" value="搜索" class="button" onclick="query()"> </div> <input type="hidden" name="catalogName" id="catalog_name" value="${catalogName}"/> <input type="hidden" name="priceStr" id="price" value="${priceStr}"/> <input type="hidden" name="currtPage" id="page" value="${currtPage}"/> <input type="hidden" name="psort" id="sort" value="${psort}"/> </form> </div> <div id="hotwords"></div> </div> <!--search end--> <div id="my360buy-2013"> <dl> <dt class="ld"><s></s><a href="http://home.jd.com/">我的京东</a><b></b></dt> <dd> <div class="loading-style1"><b></b>加载中,请稍候...</div> </dd> </dl> </div> <!--my360buy end--> <div id="settleup-2013"> <dl> <dt class="ld"><s></s><span class="shopping"><span id="shopping-amount">0</span></span><a href="http://cart.jd.com/cart/cart.html" id="settleup-url">去购物车结算</a> <b></b> </dt> <dd> <div class="prompt"> <div class="loading-style1"><b></b>加载中,请稍候...</div> </div> </dd> </dl> </div> <!--settleup end--> </div> <!--header end--> <div class="w"> <div id="nav-2013"> <div id="categorys-2013" class="categorys-2014"> <div class="mt ld"> <h2><a href="http://www.jd.com/allSort.aspx">全部商品分类<b></b></a></h2> </div> </div> <div id="treasure"></div> <ul id="navitems-2013"> <li class="fore1" id="nav-home"><a href="http://www.jd.com/">首页</a></li> <li class="fore2" id="nav-fashion"><a href="http://fashion.jd.com/">服装城</a></li> <li class="fore3" id="nav-chaoshi"><a href="http://channel.jd.com/chaoshi.html">食品</a></li> <li class="fore4" id="nav-tuan"><a href="http://tuan.jd.com/" target="_blank">团购</a></li> <li class="fore5" id="nav-auction"><a href="http://auction.jd.com/">夺宝岛</a></li> <li class="fore6" id="nav-shan"><a href="http://red.jd.com/">闪购</a></li> <li class="fore7" id="nav-jinrong"><a href="http://jr.jd.com/" target="_blank">金融</a></li> </ul> </div> </div> </div> <div class="w"> <div class="breadcrumb"> <strong><a href="#">服饰内衣</a></strong><span> > <a href="#">女装</a> > <a href="#">T恤</a></span> </div> </div> <div class="w main"> <div class="right-extra"> <div id="select" clstag="thirdtype|keycount|thirdtype|select" class="m"> <div class="mt"> <h1> T恤 -<strong> 商品筛选</strong> </h1> </div> <div class="mc attrs"> <div data-id="100001" class="brand-attr"> <div class="attr"> <div class="a-key">商品类别:</div> <div class="a-values"> <div class="v-tabs"> <div class="tabcon"> <div> <a href="javascript:filter('catalog_name', '幽默杂货')" >幽默杂货</a> </div> <div> <a href="javascript:filter('catalog_name', '时尚卫浴')">时尚卫浴</a> </div> <div> <a href="javascript:filter('catalog_name', '另类文体')">另类文体</a> </div> <div> <a href="javascript:filter('catalog_name', '创意相架')">创意相架</a> </div> <div> <a href="javascript:filter('catalog_name', '巧妙收纳')">巧妙收纳</a> </div> <div> <a href="javascript:filter('catalog_name', '与钟不同')">与钟不同</a> </div> <div> <a href="javascript:filter('catalog_name', '个性男人')">个性男人</a> </div> <div> <a href="javascript:filter('catalog_name', '电脑周边')">电脑周边</a> </div> <div> <a href="javascript:filter('catalog_name', '品质家电')">品质家电</a> </div> <div> <a href="javascript:filter('catalog_name', '品味茶杯')">品味茶杯</a> </div> <div> <a href="javascript:filter('catalog_name', '四季用品')">四季用品</a> </div> <div> <a href="javascript:filter('catalog_name', '健康宝宝')">健康宝宝</a> </div> <div> <a href="javascript:filter('catalog_name', '新潮美容')">新潮美容</a> </div> <div> <a href="javascript:filter('catalog_name', '产品配件')">产品配件</a> </div> <div> <a href="javascript:filter('catalog_name', '雅致灯饰')">雅致灯饰</a> </div> <div> <a href="javascript:filter('catalog_name', '阳光车饰')">阳光车饰</a> </div> <div> <a href="javascript:filter('catalog_name', '趣味纸抽')">趣味纸抽</a> </div> <div> <a href="javascript:filter('catalog_name', '布艺毛绒')">布艺毛绒</a> </div> <div> <a href="javascript:filter('catalog_name', '益智手工')">益智手工</a> </div> <div> <a href="javascript:filter('catalog_name', '环保餐具')">环保餐具</a> </div> <div> <a href="javascript:filter('catalog_name', '闪亮匙扣')">闪亮匙扣</a> </div> <div> <a href="javascript:filter('catalog_name', '手机饰品')">手机饰品</a> </div> <div> <a href="javascript:filter('catalog_name', '精品数码')">精品数码</a> </div> <div> <a href="javascript:filter('catalog_name', '理财钱罐')">理财钱罐</a> </div> <div> <a href="javascript:filter('catalog_name', '美味厨房')">美味厨房</a> </div> <div> <a href="javascript:filter('catalog_name', '保健按摩')">保健按摩</a> </div> <div> <a href="javascript:filter('catalog_name', '魅力女人')">魅力女人</a> </div> </div> </div> </div> </div> </div> <div data-id="100002" class="prop-attrs"> <div class="attr"> <div class="a-key">价格:</div> <div class="a-values"> <div class="v-fold"> <ul class="f-list"> <li><a href="javascript:filter('price','0-9')">0-9</a></li> <li><a href="javascript:filter('price','10-19')">10-19</a></li> <li><a href="javascript:filter('price','20-29')">20-29</a></li> <li><a href="javascript:filter('price','30-39')">30-39</a></li> <li><a href="javascript:filter('price','40-49')">40-49</a></li> <li><a href="javascript:filter('price','50-')">50以上</a></li> </ul> </div> </div> </div> </div> </div> </div> <div id="filter"> <div class="cls"></div> <div class="fore1"> <dl class="order"> <dt>排序:</dt> <dd> <a href="javascript:sort()">价格</a><b></b> </dd> </dl> <dl class="activity"> <dd></dd> </dl> <div class="pagin pagin-m"> <span class="text"><i>当前${pageList.currPage}页</i>/共${pageList.countPage}</span> <a href="javascript:changePage(-1)" class="prev">上一页<b></b></a> <a href="javascript:changePage(1)" class="next">下一页<b></b></a> </div> <div class="total"> <span>共<strong>${pageList.count}</strong>个商品 </span> </div> <span class="clr"></span> </div> </div> <!--商品列表开始--> <div id="plist" class="m plist-n7 plist-n8 prebuy"> <ul class="list-h"> <c:forEach var="p" items="${pageList.list}"> <li pid="${p.pid }"> <div class="lh-wrap"> <div class="p-img"> <a target="_blank" href="#"> <img width="220" height="282" class="err-product" src="${pageContext.request.contextPath}/images/${p.picture}"> </a> </div> <div class="p-name"> <a target="_blank" href="#">${p.pname }</a> </div> <div class="p-price"> <strong>¥${p.price}</strong><span id="p1269191543"></span> </div> </div> </li> </c:forEach> </ul> </div> <!--商品列表结束--> </div> <div class="left"> <div id="sortlist" clstag="thirdtype|keycount|thirdtype|sortlist" class="m"> <div class="mt"> <h2>服饰内衣</h2> </div> <div class="mc"> <div class="item current"> <h3> <b></b>女装 </h3> <ul> <li><a href="http://list.jd.com/1315-1343-1355.html">T恤</a></li> <li><a href="http://list.jd.com/1315-1343-1354.html">衬衫</a></li> <li><a href="http://list.jd.com/1315-1343-1356.html">针织衫</a></li> <li><a href="http://list.jd.com/1315-1343-9713.html">雪纺衫</a></li> <li><a href="http://list.jd.com/1315-1343-9710.html">卫衣</a></li> <li><a href="http://list.jd.com/1315-1343-9714.html">马甲</a></li> <li><a href="http://list.jd.com/1315-1343-9719.html">连衣裙</a></li> <li><a href="http://list.jd.com/1315-1343-9720.html">半身裙</a></li> <li><a href="http://list.jd.com/1315-1343-9715.html">牛仔裤</a></li> <li><a href="http://list.jd.com/1315-1343-9717.html">休闲裤</a></li> <li><a href="http://list.jd.com/1315-1343-9716.html">打底裤</a></li> <li><a href="http://list.jd.com/1315-1343-9718.html">正装裤</a></li> <li><a href="http://list.jd.com/1315-1343-9711.html">小西装</a></li> <li><a href="http://list.jd.com/1315-1343-9712.html">短外套</a></li> <li><a href="http://list.jd.com/1315-1343-9708.html">风衣</a></li> <li><a href="http://list.jd.com/1315-1343-9706.html">毛呢大衣</a></li> <li><a href="http://list.jd.com/1315-1343-9707.html">真皮皮衣</a></li> <li><a href="http://list.jd.com/1315-1343-9705.html">棉服</a></li> <li><a href="http://list.jd.com/1315-1343-3983.html">羽绒服</a></li> <li><a href="http://list.jd.com/1315-1343-9722.html">大码女装</a></li> <li><a href="http://list.jd.com/1315-1343-9721.html">中老年女装</a></li> <li><a href="http://list.jd.com/1315-1343-9723.html">婚纱</a></li> <li><a href="http://list.jd.com/1315-1343-11985.html">打底衫</a></li> <li><a href="http://list.jd.com/1315-1343-11986.html">旗袍/唐装</a></li> <li><a href="http://list.jd.com/1315-1343-11987.html">加绒裤</a></li> <li><a href="http://list.jd.com/1315-1343-11988.html">吊带/背心</a></li> <li><a href="http://list.jd.com/1315-1343-11989.html">羊绒衫</a></li> <li><a href="http://list.jd.com/1315-1343-11991.html">短裤</a></li> <li><a href="http://list.jd.com/1315-1343-11993.html">皮草</a></li> <li><a href="http://list.jd.com/1315-1343-11996.html">礼服</a></li> <li><a href="http://list.jd.com/1315-1343-11998.html">仿皮皮衣</a></li> <li><a href="http://list.jd.com/1315-1343-11999.html">羊毛衫</a></li> <li><a href="http://list.jd.com/1315-1343-12000.html">设计师/潮牌</a></li> </ul> </div> <div class="item"> <h3> <b></b>男装 </h3> </div> <div class="item"> <h3> <b></b>内衣 </h3> </div> <div class="item"> <h3> <b></b>服饰配件 </h3> </div> </div> </div> <div id="limitBuy"> <div id="limitbuy9199" clstag="thirdtype|keycount|thirdtype|limitbuy536" class="m limitbuy hide"> <div class="mt"> <h2>服饰鞋帽</h2> </div> <div class="mc"> <div id="clock9199" class="clock">正在加载…</div> <div id="limit9199"></div> </div> </div> </div> <div id="ad_left" reco_id="6" class="m m0 hide"></div> <!--用户最终购买--> <div id="finalbuy" class="hide m m0" style="display: block;"> <div class="mt"> <h2> 浏览<font color="red">T恤</font>最终购买 </h2> </div> <div class="mc"> </div> </div> <div id="weekRank" clstag="thirdtype|keycount|thirdtype|mrank" class="m rank"> <div class="mt"> <h2>一周销量排行</h2> </div> <div class="mc"> </div> </div> </div><!--<div class="left">--> <span class="clr"></span> <div id="Collect_Tip" class="Tip360 w260"></div> </div><!--<div class="w main">--> <div class="w"> <div id="service-2013"> <dl class="fore1"> <dt><b></b><strong>购物指南</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-56.html" target="_blank" rel="nofollow">购物流程</a></div> <div><a href="http://help.jd.com/help/question-57.html" target="_blank" rel="nofollow">会员介绍</a></div> <div><a href="http://help.jd.com/help/question-181.html" target="_blank" rel="nofollow">团购/机票</a></div> <div><a href="http://help.jd.com/help/question-61.html" target="_blank" rel="nofollow">常见问题</a></div> <div><a href="http://help.jd.com/help/question-63.html" target="_blank" rel="nofollow">大家电</a></div> <div><a href="http://help.jd.com/index.html" target="_blank" rel="nofollow">联系客服</a></div> </dd> </dl> <dl class="fore2"> <dt><b></b><strong>配送方式</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-64.html" target="_blank" rel="nofollow">上门自提</a></div> <div><a href="http://help.jd.com/help/question-360.html" target="_blank" rel="nofollow">211限时达</a></div> <div><a href="http://help.jd.com/help/distribution-768.html" target="_blank" rel="nofollow">配送服务查询</a></div> <div><a href="http://help.jd.com/help/question-892.html#help2215" target="_blank" rel="nofollow">配送费收取标准</a></div> <div><a href="http://en.jd.com/chinese.html" target="_blank">海外配送</a></div> </dd> </dl> <dl class="fore3"> <dt><b></b><strong>支付方式</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-67.html" target="_blank" rel="nofollow">货到付款</a></div> <div><a href="http://help.jd.com/help/question-68.html" target="_blank" rel="nofollow">在线支付</a></div> <div><a href="http://help.jd.com/help/question-71.html" target="_blank" rel="nofollow">分期付款</a></div> <div><a href="http://help.jd.com/help/question-69.html" target="_blank" rel="nofollow">邮局汇款</a></div> <div><a href="http://help.jd.com/help/question-70.html" target="_blank" rel="nofollow">公司转账</a></div> </dd> </dl> <dl class="fore4"> <dt><b></b><strong>售后服务</strong></dt> <dd> <div><a href="http://myjd.jd.com/afs/help/afshelp.action" target="_blank" rel="nofollow">售后政策</a></div> <div><a href="http://help.jd.com/help/question-99.html" target="_blank" rel="nofollow">价格保护</a></div> <div><a href="http://help.jd.com/help/question-100.html" target="_blank" rel="nofollow">退款说明</a></div> <div><a href="http://myjd.jd.com/repair/repairs.action" target="_blank" rel="nofollow">返修/退换货</a></div> <div><a href="http://help.jd.com/help/question-881.html" target="_blank" rel="nofollow">取消订单</a></div> </dd> </dl> <dl class="fore5"> <dt><b></b><strong>特色服务</strong></dt> <dd> <div><a href="http://help.jd.com/help/question-79.html" target="_blank">夺宝岛</a></div> <div><a href="http://help.jd.com/help/question-86.html" target="_blank">DIY装机</a></div> <div><a href="http://fuwu.jd.com/" target="_blank" rel="nofollow">延保服务</a></div> <div><a href="http://giftcard.jd.com/market/index.action" target="_blank" rel="nofollow">京东E卡</a></div> <div><a href="http://help.jd.com/help/question-91.html" target="_blank" rel="nofollow">节能补贴</a></div> <div><a href="http://mobile.jd.com/" target="_blank" rel="nofollow">京东通信</a></div> </dd> </dl> <span class="clr"></span> </div> </div><!-- service end --><div class="w"> <div id="footer-2013"> <div class="links"> <a rel="nofollow" target="_blank" href="http://www.jd.com/intro/about.aspx">关于我们</a>|<a rel="nofollow" target="_blank" href="http://www.jd.com/contact/">联系我们</a>|<a rel="nofollow" target="_blank" href="http://zhaopin.jd.com/">人才招聘</a>|<a rel="nofollow" target="_blank" href="http://www.jd.com/contact/joinin.aspx">商家入驻</a>|<a rel="nofollow" target="_blank" href="http://sale.jd.com/act/y3surX7qpM.html">广告服务</a>|<a rel="nofollow" target="_blank" href="http://app.jd.com/">手机京东</a>|<a target="_blank" href="http://club.jd.com/links.aspx">友情链接</a>|<a target="_blank" href="http://cps.jd.com/">销售联盟</a>|<a href="http://club.jd.com/" target="_blank">京东社区</a>|<a href="http://gongyi.jd.com/" target="_blank">京东公益</a></div> <div class="copyright">北京市公安局朝阳分局备案编号110105014669 | 京ICP证070359号 | 互联网药品信息服务资格证编号(京)-非经营性-2011-0034<br><a rel="nofollow" href="http://misc.360buyimg.com/skin/df/i/com/f_music.jpg" target="_blank">音像制品经营许可证苏宿批005号</a>| 出版物经营许可证编号新出发(苏)批字第N-012号 | 互联网出版许可证编号新出网证(京)字150号<br><a href="http://misc.360buyimg.com/wz/wlwhjyxkz.jpg" target="_blank">网络文化经营许可证京网文[2011]0168-061号</a>Copyright © 2004-2015 京东JD.com 版权所有<br>京东旗下网站:<a href="http://en.jd.com/" target="_blank">English Site</a></div> <div class="authentication"><a rel="nofollow" target="_blank" href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202007080200026"><img width="108" height="40" alt="经营性网站备案中心" src="<c:url value='/resource'/>/108_40_zZOKnl.gif" class="err-product"></a> <a rel="nofollow" target="_blank" tabindex="-1" href="https://ss.cnnic.cn/verifyseal.dll?sn=2008070300100000031&ct=df&pa=294005" id="urlknet"><img width="108" height="40" border="true" name="CNNIC_seal" alt="可信网站" src="<c:url value='/resource'/>/kxwz.gif" class="err-product"></a> <a rel="nofollow" target="_blank" href="http://www.bj.cyberpolice.cn/index.do"><img width="108" height="40" alt="朝阳网络警察" src="<c:url value='/resource'/>/cywljc.png" class="err-product"></a> <a rel="nofollow" target="_blank" href="https://search.szfw.org/cert/l/CX20120111001803001836"><img width="112" height="40" src="<c:url value='/resource'/>/112_40_WvArIl.png" class="err-product"></a> </div> </div> </div> </body> </html>
12.编写实体类Products
package com.bianyiit.pojo; import lombok.Data; import org.apache.solr.client.solrj.beans.Field; import java.util.Date; @Data public class Products { @Field("id") private String pid; @Field("prod_pname") private String pname; private Integer catalog; @Field("prod_catalog_name") private String catalogName; @Field("prod_price") private Double price; private Integer number; @Field("prod_picture") private String picture; private Date releaseTime; @Field("prod_description") private String description; }
13.编写分页工具类PageUtils
package com.bianyiit.utils; import lombok.Data; import java.util.List; /* * 分页工具类 */ @Data public class PageUtils { private int pageSize; // 每页大小 private int currPage;// 当前页数 private int offset; // 偏移量,也就是limit中的起始页数start private int count; // 总记录数 private int countPage;// 总页数 private List<?> list;// ?未知的数据类型 用于存放分页显示的数据信息 public PageUtils(int count, int pageSize, int currPage) { if(pageSize>1){ this.pageSize=pageSize; }else{ this.pageSize=5; } if(currPage>1){ this.currPage=currPage; }else{ this.currPage=1; } //得到总页数 this.countPage=count%pageSize==0?count/pageSize:count/pageSize+1; //总记录数 this.count=count; //偏移量 this.offset=(this.currPage-1)*this.pageSize; } }
14.在web层编写ProductController
package com.bianyiit.web; import com.bianyiit.service.ProductService; import com.bianyiit.utils.PageUtils; import org.apache.solr.client.solrj.SolrServerException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import java.io.IOException; @Controller @RequestMapping("/product") public class ProductController { @Autowired private ProductService productService; @RequestMapping("/get") public ModelAndView get(String keyword, String catalogName, String priceStr, @RequestParam(defaultValue = "1") String currtPage, String psort) throws IOException, SolrServerException { ModelAndView modelAndView=new ModelAndView(); PageUtils pageUtils = productService.search(keyword, catalogName, priceStr, psort, Integer.valueOf(currtPage), 9); /*将数据添加到作用域中*/ modelAndView.addObject("pageList",pageUtils); modelAndView.addObject("keyword",keyword); modelAndView.addObject("catalogName",catalogName); modelAndView.addObject("priceStr",priceStr); modelAndView.addObject("psort",psort); modelAndView.addObject("currtPage",currtPage); modelAndView.setViewName("/jd.jsp"); return modelAndView; } }
15.在service层编写ProductService接口和ProductServiceImpl实现类
package com.bianyiit.service;
import com.bianyiit.utils.PageUtils;
import org.apache.solr.client.solrj.SolrServerException;
import java.io.IOException;
public interface ProductService {
/*通过pagehepler插件返回一个Page集合*/
PageUtils search(String keyword, String catalogName, String priceStr, String psort, Integer currtPage, Integer pageSize) throws IOException, SolrServerException;
}
package com.bianyiit.service.impl; import com.bianyiit.pojo.Products; import com.bianyiit.service.ProductService; import com.bianyiit.utils.PageUtils; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.response.QueryResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.io.IOException; import java.util.List; import java.util.Map; @Service public class ProductServiceImpl implements ProductService{ @Autowired private HttpSolrClient httpSolrClient; @Override public PageUtils search(String keyword, String catalogName, String priceStr, String psort, Integer currtPage, Integer pageSize) throws IOException, SolrServerException { SolrQuery solrQuery=new SolrQuery(); /*主页关键字判断*/ if(StringUtils.isEmpty(keyword)){ solrQuery.set("q","*:*"); }else{ solrQuery.set("q","prod_pname:"+keyword); } /*类别筛选*/ if(!StringUtils.isEmpty(catalogName)){ solrQuery.addFilterQuery("prod_catalog_name:"+catalogName); } /*价格过滤*/ if(!StringUtils.isEmpty(priceStr)){ String[] split = priceStr.split("-"); if(split.length==2){ solrQuery.addFilterQuery("prod_price:["+split[0]+" TO "+split[1]+"]"); }else{ solrQuery.addFilterQuery("prod_price:["+split[0]+" TO *]"); } } /*进行排序*/ if(!StringUtils.isEmpty(psort)){ if(psort.equals("1")){ solrQuery.addSort("prod_price",SolrQuery.ORDER.asc); }else if(psort.equals("0")){ solrQuery.addSort("prod_price",SolrQuery.ORDER.desc); } } /*设置高亮功能*/ solrQuery.setHighlight(true); solrQuery.addHighlightField("prod_pname"); solrQuery.setHighlightSimplePre("<font color='red'>"); solrQuery.setHighlightSimplePost("</font>"); /*设置solr分页查询*/ solrQuery.setStart((currtPage-1)*pageSize); solrQuery.setRows(pageSize); /*solr客户端进行数据查询*/ QueryResponse queryResponse = httpSolrClient.query(solrQuery); /*先用标红的关键字去替换原来查询出来的数据*/ Map<String, Map<String, List<String>>> map = queryResponse.getHighlighting(); List<Products> productsList = queryResponse.getBeans(Products.class); /*然后去map集合中的用标红的关键字去替换productsList集合中的数据*/ for (Products p : productsList) { Map<String, List<String>> map1 = map.get(p.getPid()); List<String> list = map1.get("prod_pname"); if(list!=null){ String resultPname = list.get(0); p.setPname(resultPname); } } //获得总记录数 int count = (int) queryResponse.getResults().getNumFound(); /*将所有的信息全部封装到PageUtils里面*/ PageUtils pageUtils=new PageUtils(count,pageSize,currtPage); pageUtils.setList(productsList); return pageUtils; } }
16.在sqlyog中执行下述sql创建solr数据库,创建product表并添加数据
链接:https://pan.baidu.com/s/1ZBwR-LJCbmWdkL58EeX46Q
提取码:fmrs
17.打开D:\solr\apache-tomcat-8.5.50-solr-8081\bin目录下的startup.bat,启动solr服务器
18.在Idea中添加Tomcat,添加项目至Tomcat,启动Tomcat发布项目
19.启动成功,默认自动打开浏览器访问http://localhost:8080/
20.点击搜索,查看从solr服务器进行全文检索的商品信息
21.在搜索框输入关键字,进行全文检索,并将商品名称中符合的索引标红显示
保存在数据库中的商品信息表高达3803条记录,如果使用sql语句查询效率太低,这时采用全文检索技术,将数据库中内容进行中文分词,去掉停用词,然后将数据库表中的一些字段生成索引,采用全文检索进行查询比直接使用顺序扫描效率要高得多!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。