打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
淘淘商城8.6

继续八月五号写的,今天晚上花点时间开发这个项目,过程如下:

1、测试Maven工程

1.1、创建欢迎页

在webapp下创建一个index.jsp的欢迎页

index.jsp:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  7. <title>欢迎管理taotao-manager</title>  
  8. </head>  
  9. <body>  
  10.     <h1>  
  11.         如果你看到此页面,说明taotao-manager已经运行  
  12.     <h1>  
  13. </body>  
  14. </html>  

1.2、要运行的工程

要运行工程,需要运行聚合工程也就是taotao-manager。


1.3、配置Tomcat插件

在taotao-manager工程的pom文件中添加如下内容:

  1. <build>  
  2.     <!-- 配置插件 -->  
  3.     <plugins>  
  4.         <plugin>  
  5.             <groupId>org.apache.tomcat.maven</groupId>  
  6.             <artifactId>tomcat7-maven-plugin</artifactId>  
  7.             <configuration>  
  8.                 <port>8080</port>  
  9.                 <path>/</path>  
  10.             </configuration>  
  11.         </plugin>  
  12.     </plugins>  
  13. </build>  

1.4、启动工程



在浏览器上输入http://localhost:8080/

注意:

如果运行将taotao-manager运行在tomcat出错,执行下面两步:

1、需要把taotao-parent工程安装到本地仓库。Install

2、需要把taotao-common安装到本地仓库。install


2、创建数据库

使用mysql数据库。这里我提供数据库脚本taotao.sql,下载地址:http://pan.baidu.com/s/1kUMO4SJ


我这里是在CentOS7上搭建数据库系统,详情可以参考我的另一篇博客:CentOS7上安装mysql,链接地址:http://blog.csdn.net/sinat_31726559/article/details/51955125

然后用nativeCat连接上远程数据库,在mysql里面新建一个taotao的数据库,右键运行sql文件,将taotao.sql文件运行在taotao的数据库中,显示成功后就会导入项目中我们要用到的所有表。

注意:在互联网行业的项目中尽可能的减少表的管理查询。使用冗余解决表的关联问题。有利于分库分表。

商品表:


Sku:最小库存量单位。就是商品id。就是商品最细力度的划分。每个sku都唯一对应一款商品,商品的颜色、配置都已经唯一确定。

3、逆向工程

Mybatis的逆向工程。根据数据库表生成java代码。详细教程可参考:http://www.tuicool.com/articles/ABbqqie

这里我给大家提供好我这边能跑的官网工程,上面的配置文件是按照我机器上面的信息配置的,你们用的时候要记得将上面的一部分信息修改成符合你机器,逆向工程下载地址我已经上传到我的云盘里,链接是:http://pan.baidu.com/s/1qYvknrm

3.1、导入工程




3.2、修改generatorConfi.xml

generatorConfig.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE generatorConfiguration  
  3.   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  4.   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  
  5.   
  6. <generatorConfiguration>  
  7.     <context id="testTables" targetRuntime="MyBatis3">  
  8.         <commentGenerator>  
  9.             <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
  10.             <property name="suppressAllComments" value="true" />  
  11.         </commentGenerator>  
  12.   
  13.         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->  
  14.         <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
  15.             <span style="color:#FF0000;">connectionURL="jdbc:mysql://192.168.43.163:3306/taotao" userId="root"  
  16.             password="115010"></span>  
  17.         </jdbcConnection>  
  18.   
  19.         <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL   
  20.             和 NUMERIC 类型解析为java.math.BigDecimal -->  
  21.         <javaTypeResolver>  
  22.             <property name="forceBigDecimals" value="false" />  
  23.         </javaTypeResolver>  
  24.   
  25.         <!-- targetProject:生成PO类的位置 -->  
  26.         <javaModelGenerator targetPackage="com.taotao.pojo"  
  27.             targetProject=".\src">  
  28.             <!-- enableSubPackages:是否让schema作为包的后缀 -->  
  29.             <property name="enableSubPackages" value="false" />  
  30.             <!-- 从数据库返回的值被清理前后的空格 -->  
  31.             <property name="trimStrings" value="true" />  
  32.         </javaModelGenerator>  
  33.   
  34.         <!-- targetProject:mapper映射文件生成的位置 -->  
  35.         <sqlMapGenerator targetPackage="com.taotao.mapper"  
  36.             targetProject=".\src">  
  37.             <!-- enableSubPackages:是否让schema作为包的后缀 -->  
  38.             <property name="enableSubPackages" value="false" />  
  39.         </sqlMapGenerator>  
  40.   
  41.         <!-- targetPackage:mapper接口生成的位置 -->  
  42.         <javaClientGenerator type="XMLMAPPER"  
  43.             targetPackage="com.taotao.mapper" targetProject=".\src">  
  44.             <!-- enableSubPackages:是否让schema作为包的后缀 -->  
  45.             <property name="enableSubPackages" value="false" />  
  46.         </javaClientGenerator>  
  47.   
  48.         <!-- 指定数据库表 -->  
  49.         <table schema="" tableName="tb_content"></table>  
  50.         <table schema="" tableName="tb_content_category"></table>  
  51.         <table schema="" tableName="tb_item"></table>  
  52.         <table schema="" tableName="tb_item_cat"></table>  
  53.         <table schema="" tableName="tb_item_desc"></table>  
  54.         <table schema="" tableName="tb_item_param"></table>  
  55.         <table schema="" tableName="tb_item_param_item"></table>  
  56.         <table schema="" tableName="tb_order"></table>  
  57.         <table schema="" tableName="tb_order_item"></table>  
  58.         <table schema="" tableName="tb_order_shipping"></table>  
  59.         <table schema="" tableName="tb_user"></table>  
  60.   
  61.     </context>  
  62. </generatorConfiguration>  

3.3、运行逆向工程


运行成功后会产生上面两个java包下的代码。

4、SSM框架整合

4.1、整合思路

4.1.1、Dao层

使用mybatis框架。创建SqlMapConfig.xml。

创建一个applicationContext-dao.xml

1、配置数据源

2、需要让spring容器管理SqlsessionFactory,单例存在。

3、把mapper的代理对象放到spring容器中。使用扫描包的方式加载mapper的代理对象。

4.1.2、Service层

1、事务管理

2、需要把service实现类对象放到spring容器中管理。

4.1.3、表现层

1、配置注解驱动

2、配置视图解析器

3、需要扫描controller

4.1.4、Web.xml

1、spring容器的配置

2、Springmvc前端控制器的配置

3、Post乱码过滤器

4.2、框架整合

  首先思考我们这些配置文件应该放在我们创建的哪个工程下?

  答:就我思考,首先我们应该理解配置文件是干什么用的,假如我将配置文件放在taotao-manager-pojo下,他是一个jar形式的工程,开发完后会打包成jar放到lib下,这样程序就读不到配置文件了,所以这里我们应该放到war的工程下。

 

需要把配置文件放到taotao-manager-web工程下。因为此工程为war工程,其他的工程只是一个jar包。

4.2.1、mybatis整合

整合后的工程结构图如下所示:


SqlMapConfig.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE configuration  
  3.         PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
  4.         "http://mybatis.org/dtd/mybatis-3-config.dtd">  
  5. <configuration>  
  6.   
  7. </configuration>  

applicationContext-dao.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  7.     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  8.     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd   
  9.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
  10.     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">  
  11.   
  12.     <!-- 数据库连接池 -->  
  13.     <!-- 加载配置文件 -->  
  14.     <context:property-placeholder location="classpath:resource/db.properties" />  
  15.     <!-- 数据库连接池 阿里的开源连接池-->  
  16.     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  
  17.         destroy-method="close">  
  18.         <property name="url" value="${jdbc.url}" />  
  19.         <property name="username" value="${jdbc.username}" />  
  20.         <property name="password" value="${jdbc.password}" />  
  21.         <property name="driverClassName" value="${jdbc.driver}" />  
  22.         <property name="maxActive" value="10" />  
  23.         <property name="minIdle" value="5" />  
  24.     </bean>  
  25.     <!-- 配置sqlsessionFactory -->  
  26.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  27.         <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>  
  28.         <property name="dataSource" ref="dataSource"></property>  
  29.     </bean>  
  30.     <!-- 配置扫描包,加载mapper代理对象 -->  
  31.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  32.         <property name="basePackage" value="com.taotao.mapper"></property>  
  33.     </bean>  
  34. </beans>  

4.2.2、Service层

applicationContext-service.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  7.     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  8.     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd   
  9.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
  10.     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">  
  11.   
  12.     <!-- 扫描包加载Service实现类 -->  
  13.     <context:component-scan base-package="com.taotao.service"></context:component-scan>  
  14. </beans>  

applicationContext-trans.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  7.     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  8.     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd   
  9.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
  10.     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">  
  11.   
  12.     <!-- 事务管理器 -->  
  13.     <bean id="transactionManager"  
  14.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  15.         <!-- 数据源 -->  
  16.         <property name="dataSource" ref="dataSource" />  
  17.     </bean>  
  18.     <!-- 通知 -->  
  19.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  20.         <tx:attributes>  
  21.             <!-- 传播行为 -->  
  22.             <tx:method name="save*" propagation="REQUIRED" />  
  23.             <tx:method name="insert*" propagation="REQUIRED" />  
  24.             <tx:method name="add*" propagation="REQUIRED" />  
  25.             <tx:method name="create*" propagation="REQUIRED" />  
  26.             <tx:method name="delete*" propagation="REQUIRED" />  
  27.             <tx:method name="update*" propagation="REQUIRED" />  
  28.             <tx:method name="find*" propagation="SUPPORTS" read-only="true" />  
  29.             <tx:method name="select*" propagation="SUPPORTS" read-only="true" />  
  30.             <tx:method name="get*" propagation="SUPPORTS" read-only="true" />  
  31.         </tx:attributes>  
  32.     </tx:advice>  
  33.     <!-- 切面 -->  
  34.     <aop:config>  
  35.         <aop:advisor advice-ref="txAdvice"  
  36.             pointcut="execution(* com.taotao.service.*.*(..))" />  
  37.     </aop:config>  
  38. </beans>  

4.2.3、表现层

springmvc.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  
  8.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  9.   
  10.     <context:component-scan base-package="com.taotao.controller" />  
  11.     <mvc:annotation-driven />  
  12.     <bean  
  13.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  14.         <property name="prefix" value="/WEB-INF/jsp/" />  
  15.         <property name="suffix" value=".jsp" />  
  16.     </bean>  
  17. </beans>  

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  5.     id="taotao" version="2.5">  
  6.     <display-name>taotao-manager</display-name>  
  7.     <welcome-file-list>  
  8.         <welcome-file>index.html</welcome-file>  
  9.         <welcome-file>index.htm</welcome-file>  
  10.         <welcome-file>index.jsp</welcome-file>  
  11.         <welcome-file>default.html</welcome-file>  
  12.         <welcome-file>default.htm</welcome-file>  
  13.         <welcome-file>default.jsp</welcome-file>  
  14.     </welcome-file-list>  
  15.     <!-- 加载spring容器 -->  
  16.     <context-param>  
  17.         <param-name>contextConfigLocation</param-name>  
  18.         <param-value>classpath:spring/applicationContext-*.xml</param-value>  
  19.     </context-param>  
  20.     <listener>  
  21.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  22.     </listener>  
  23.     <!-- 解决post乱码 -->  
  24.     <filter>  
  25.         <filter-name>CharacterEncodingFilter</filter-name>  
  26.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  27.         <init-param>  
  28.             <param-name>encoding</param-name>  
  29.             <param-value>utf-8</param-value>  
  30.         </init-param>  
  31.     </filter>  
  32.     <filter-mapping>  
  33.         <filter-name>CharacterEncodingFilter</filter-name>  
  34.         <url-pattern>/*</url-pattern>  
  35.     </filter-mapping>  
  36.     <!-- springmvc的前端控制器 -->  
  37.     <servlet>  
  38.         <servlet-name>taotao-manager</servlet-name>  
  39.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  40.         <!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation,   
  41.                      springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->  
  42.         <init-param>  
  43.             <param-name>contextConfigLocation</param-name>  
  44.             <param-value>classpath:spring/springmvc.xml</param-value>  
  45.         </init-param>  
  46.         <load-on-startup>1</load-on-startup>  
  47.     </servlet>  
  48.     <servlet-mapping>  
  49.         <servlet-name>taotao-manager</servlet-name>  
  50.         <span style="color:#FF0000;"><url-pattern>/</url-pattern></span>  
  51.     </servlet-mapping>  
  52. </web-app>  

注意:标红部分的"/"会拦截所有请求包括静态资源。需要在springmvc.xml中添加静态资源的映射。

修改完的springmvc如下:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  
  8.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  9.   
  10.     <context:component-scan base-package="com.taotao.controller" />  
  11.     <mvc:annotation-driven />  
  12.     <bean  
  13.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  14.         <property name="prefix" value="/WEB-INF/jsp/" />  
  15.         <property name="suffix" value=".jsp" />  
  16.     </bean>  
  17.       
  18.     <!-- 资源映射 -->  
  19.     <mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>  
  20.     <mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>  
  21.       
  22. </beans>  

4.2.4、添加后台管理的静态资源页面

这部分的资源我已经上传到云盘,下载链接是:http://pan.baidu.com/s/1qYIkRIO

将里面的静态资源复制粘贴到WEB-INF下面,如图:

4.3、整合讨论

这里我们考虑一下为啥不直接用全局扫描呢?

答:首先我们要理解springmvc和spring的父子容器关系,如下图所示:

例如:

在applicationContext-service中配置:

  1. <!-- 扫描包加载Service实现类 -->  
  2. <context:component-scan base-package="com.taotao"></context:component-scan>  

会扫描@Controller@Service@Repository@Compnent

Springmvc.Xml中不扫描。

结果:springmvc。不能提供服务,因为springmvc子容器中不扫描会没有controller对象

所以这里我们不能去配置全局扫描,会找不到对象的。


5、整合测试

5.1、测试需求

这里我们就做个根据商品id查询商品信息。

5.2、SQL语句

  1. SELECT * from tb_item WHERE id=536563  

5.3、Dao层

使用逆向工程生成的mapper文件

5.4、Service层

接收商品id调用dao查询商品信息。返回商品pojo对象,代码如下:

定义一个ItemService接口:

  1. package com.taotao.service;  
  2.   
  3. import com.taotao.pojo.TbItem;  
  4.   
  5. /** 
  6.  *  
  7.   * @ClassName: ItemService   
  8.   * @Description: TODO(商品管理的itemService接口)   
  9.   * @author 汪本成   
  10.   * @date 2016年8月6日 下午10:31:12   
  11.   * 
  12.  */  
  13. public interface ItemService {  
  14.       
  15.     TbItem getItemById(long itemId);  
  16.   
  17. }  

设计一个ItemService的实现类

  1. package com.taotao.service.impl;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.stereotype.Service;  
  7.   
  8. import com.taotao.mapper.TbItemMapper;  
  9. import com.taotao.pojo.TbItem;  
  10. import com.taotao.pojo.TbItemExample;  
  11. import com.taotao.pojo.TbItemExample.Criteria;  
  12. import com.taotao.service.ItemService;  
  13.   
  14. /** 
  15.  *  
  16.   * @ClassName: ItemServiceImpl   
  17.   * @Description: TODO(商品管理的ItemService)   
  18.   * @author 汪本成   
  19.   * @date 2016年8月6日 下午10:30:28   
  20.   * @version 1.0 
  21.  */  
  22.   
  23.   
  24. @Service  
  25. public class ItemServiceImpl implements ItemService {  
  26.       
  27.     @Autowired  
  28.     private TbItemMapper itemMapper;  
  29.   
  30.     @Override  
  31.     public TbItem getItemById(long itemId) {  
  32.         // TODO Auto-generated method stub  
  33.           
  34.         /** 
  35.          * 1、根据主键查询 
  36.          * 
  37.         //TbItem item = itemMapper.selectByPrimaryKey(itemId); 
  38.          
  39.         /** 
  40.          * 2、根据条件进行查询 
  41.          */  
  42.         //添加查询条件  
  43.         TbItemExample example = new TbItemExample();  
  44.         Criteria criteria = example.createCriteria();  
  45.         criteria.andIdEqualTo(itemId);  
  46.         //返回查询结果到List中  
  47.         List<TbItem> list = itemMapper.selectByExample(example);  
  48.         //进行判断  
  49.         if(null != list && list.size() > 0) {  
  50.             TbItem item = list.get(0);  
  51.             return item;  
  52.         }  
  53.         return null;  
  54.     }  
  55.   
  56. }  

5.5、Controller层

接收页面请求商品id,调用service查询商品信息。直接返回一个json数据。需要使用@ResponseBody注解。

  1. package com.taotao.controller;  
  2.   
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.stereotype.Controller;  
  5. import org.springframework.web.bind.annotation.PathVariable;  
  6. import org.springframework.web.bind.annotation.RequestMapping;  
  7. import org.springframework.web.bind.annotation.ResponseBody;  
  8.   
  9. import com.taotao.pojo.TbItem;  
  10. import com.taotao.service.ItemService;  
  11.   
  12. /** 
  13.  *  
  14.   * @ClassName: ItemController   
  15.   * @Description: TODO(调用ItemService查询商品信息)   
  16.   * @author 汪本成   
  17.   * @date 2016年8月6日 下午10:49:53   
  18.   * 
  19.  */  
  20.   
  21. @Controller  
  22. public class ItemController {  
  23.   
  24.     @Autowired  
  25.     private ItemService itemService;  
  26.       
  27.     @RequestMapping("/item/{itemId}")  
  28.     @ResponseBody  
  29.     public TbItem getItemById(@PathVariable Long itemId) {  
  30.         TbItem tbItem = itemService.getItemById(itemId);  
  31.         return tbItem;  
  32.     }  
  33. }  

5.6、查询结果

启动taotao-manager之后,打开浏览器输入http://localhost:8080/item/536563,会报错,如下:


这个错误的解决也很简单

修改taotao-manager-mapper的pom文件,在文件中添加下面内容就好

  1. <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->  
  2.     <build>  
  3.         <resources>  
  4.             <resource>  
  5.                 <directory>src/main/java</directory>  
  6.                 <includes>  
  7.                     <include>**/*.properties</include>  
  8.                     <include>**/*.xml</include>  
  9.                 </includes>  
  10.                 <filtering>false</filtering>  
  11.             </resource>  
  12.         </resources>  
  13.     </build>  

修改完之后刷新页面,如下:

测试ok!

,明天继续,欢迎关注,一直分享干货中。







本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
@Service注解使用
SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)
如何使用Spring架构中的注释功能
Spring HTTP Invoker例子
Spring 注解学习手札
spring @WebService 注解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服