淘淘商城(SpringMVC+Spring+Mybatis)  是传智播客在2015年9月份录制的,几年过去了。由于视频里课上老师敲的代码和项目笔记有些细节上存在出入,只有根据日志报错信息作出适当的调整变更才能跑通项目。为了方便广大自学Java同仁的共同进步,我将持续更新这个网络实战项目练习的内容,着重指出符合当下开发环境下的内容勘误修订。

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040

第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第一天】

第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第二天】

第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第三天】

02.第二天(框架整合,后台系统搭建)


    @Override
public User getUserById(Long id) {
// 方法一:适用于任何字段的查询
Example example = new Example(User.class);
example.createCriteria().andEqualTo("id", id);
List<User> list = userMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
} else {
return null;
}
// 方法二:只适用于主键字段
return userMapper.selectByPrimaryKey(id);
}

mybatis逆向工程的根据example对象查询的使用

一、Eclipse中运行提示报错:[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

09.整合测试-ok.avi

在按照视频中老师的讲解按部就班的操作下,Eclipse中运行提示报错:[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

这是因为我全新安装的eclipse&maven没有对编译jdk版本配置导致。修正方法在我的CSDN博客  https://blog.csdn.net/qq_40993412/article/details/99322387

二、maven 编译出错 Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean

eclipse在使用maven的tomcat7插件编译java程序时,报错 Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project **-web: Failed to clean project: Failed to delete X:\**\target\tomcat\logs\access_log

出现这种错误,通常是由于您已启动了另一个tomcat 进程或者运行的javaw.exe进程。控制台先关掉之前运行的那个tomcat进程,再重新操作就行了。

三、Mybatis的逆向工程。根据数据库表生成实体类的java代码。

File—>Import—>

generatorSqlmapCustom

因为该独立项目的依赖的jar包被我更新成别的文件版本,所以显示红色叹号提示,需要我们去Properties从新配置。

把红色小奶瓶的jar包依赖Remove后,点击Apply and Close 就能解决这个问题。

 

三、 taotao商城项目视频中老师所创建的web项目文件路径和附件中笔记、教案提供的参考源代码有出入导致的报错

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'itemController':
Could not autowire field: private com.taotao.service.ItemService com.taotao.controller.ItemController.itemService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.taotao.service.ItemService] found for dependency:

说明原理的一个技术博客链接  https://blog.csdn.net/s740556472/article/details/54974074

四、log4j日志输出配置文件未设置导致的报错解决

在视频中,老师一直没提log4j的配置文件log4j.properties的设定,导致后面完全按照演示操作也会出现Eclipse提示报错信息:

log4j:WARN No appenders could be found for logger
log4j:WARN Please initialize the log4j system properly

01.参考资料文件夹里面有log4j.properties文件,我们需要把它复制到项目resources目录或将log4j.properties放到 \WEB-INF\classes文件夹中即可。

参考的技术博客:   关于控制台输出 警告 log4j:WARN No appenders could be found for logger

将src文件夹设置为source目录方法

五、由于配置加载db.properties路径错误导致的cannot be resolved to URL because it does not exist异常处理

参考的技术博客 https://blog.csdn.net/qinkang1993/article/details/57626434/

淘淘商城项目照着视频做出现这个报错,原因是老师提供的教案配置信息和视频演示有些小出入,需要我们自行修改.xml配置文件。

把下图中高亮的首个properties改成视频课中的实际文件路径resource问题解决。

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=UTF-8&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=root

六、阿里巴巴的druid数据库连接池配置文件 db.properties 要注意格式

2019年我在复盘这个taotao商城项目的时候,可以通过taotao-parent定义依赖的版本更新到

<druid.version>1.1.10</druid.version>

//北京时间东八区
serverTimezone=GMT%2B8
//或者使用上海时间
serverTimezone=Asia/Shanghai

在taotao-manager-web项目下的 src/main/resources 有spring文件夹,里面的applicationContext-dao.xml 定义了druid数据库连接池的配置信息。

 <!-- 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="maxActive" value="20" />
<property name="initialSize" value="1" />
<property name="maxWait" value="60000" />
<property name="minIdle" value="5" />
</bean>

参考的技术博客  JDBC连接数据库 mysql serverTimezone useSSL 时差

DRUID连接池的实用 配置详解

七、在taotao-manager-web项目下的pom.xml里 ,配置tomcat插件的warSourceDirectory标签。

  <build>
<plugins>
<!-- 配置Tomcat插件的warSourceDirectory -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins> </build>

八、mybatis 整合spring之mapperLocations配置的问题

结论是:如果Mapper.xml与Mapper.class在同一个包下且同名,spring扫描Mapper.class的同时会自动扫描同名的Mapper.xml并装配到Mapper.class。

如果Mapper.xml与Mapper.class不在同一个包下或者不同名,就必须使用配置mapperLocations指定mapper.xml的位置。

九、分页测试给web项目pom.xml导入分页插件的依赖坐标不能用最新版而要用附件中老师修改过的特别版本3.4.2-fix

// taotao-parent中定义的版本不能用5.X.X因为会抛出异常
<pagehelper.version>3.4.2-fix</pagehelper.version>

十、修改taotao-manager-mapper的pom.xml文件中添加如下内容:

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

Service层的实现类 根据商品ID查询方法:

    @Override
public TbItem getItemById(long itemId) {
//方法一、根据主键查询
//TbItem item = itemMapper.selectByPrimaryKey(itemId);
//方法二、添加查询条件,适用于任何字段的查询
//1.创建一个TbItemExample实例对象example
TbItemExample example = new TbItemExample();
//2.实例对象example.createCriteria()
Criteria criteria = example.createCriteria();
//3.criteria.andIdEqualTo()
criteria.andIdEqualTo(itemId);
//4.selectByExample(example)返回结果
List<TbItem> list = itemMapper.selectByExample(example); if (list != null && list.size() > 0) {
//从List集合中取出索引为0的对象
TbItem item = list.get(0);
return item;
}
return null;
}

http://localhost:8080/item/536563

11. Service层的查询所有并分页的代码

    @Override
public EUDataGridResult getItemList(int page, int rows) {
// 查询商品列表
TbItemExample example = new TbItemExample();
// 分页处理
PageHelper.startPage(page, rows);
List<TbItem> list = itemMapper.selectByExample(example);
// 创建一个返回值对象
EUDataGridResult result = new EUDataGridResult();
result.setRows(list);
// 取记录总条数
PageInfo<TbItem> pageInfo = new PageInfo<TbItem>(list);
result.setTotal(pageInfo.getTotal());
return result; }

12.分页查询会报错,原因是淘淘项目mybatis的版本最高支持到3.2.8版本

    <!-- 集中定义依赖版本号 -->
<properties>
<junit.version>4.12</junit.version>
<spring.version>4.3.25.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.3.3</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<pagehelper.version>3.4.2-fix</pagehelper.version>
<mysql.version>5.1.45</mysql.version>
<slf4j.version>1.7.25</slf4j.version>
<jackson.version>2.9.9.3</jackson.version>
<druid.version>1.1.10</druid.version>
<httpclient.version>4.5.6</httpclient.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>3.1.0</servlet-api.version>
<jsp-api.version>2.2</jsp-api.version>
<joda-time.version>2.9.9</joda-time.version>
<commons-lang3.version>3.9</commons-lang3.version>
<commons-io.version>2.6</commons-io.version>
<commons-net.version>3.6</commons-net.version>
<jsqlparser.version>0.9.1</jsqlparser.version>
<commons-fileupload.version>1.4</commons-fileupload.version>
<jedis.version>2.7.2</jedis.version>
<solrj.version>4.10.3</solrj.version>
</properties>

==============================

参考资料:

SpringBoot整合MyBatis逆向工程及 MyBatis通用Mapper实例详解

okey

第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第二天】的更多相关文章

  1. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第一天】

    本人做过一年的MATLAB编程和简单维护过VB和C++的项目.是跟着网上获得的黑马的Java双元视频课来自学入门Java知识和常用框架的使用. 淘淘商城(SpringMVC+Spring+Mybati ...

  2. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第六天】

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  3. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第五天】

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  4. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第四天】

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  5. 第04项目:淘淘商城(SpringMvc+Spring+Mybatis) 的学习实践总结【第三天】

    淘淘商城(SpringMVC+Spring+Mybatis)  是传智播客在2015年9月份录制的,几年过去了.由于视频里课上老师敲的代码和项目笔记有些细节上存在出入,只有根据日志报错信息作出适当的调 ...

  6. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十天】(单点登录系统实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  7. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第九天】(商品详情页面实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  8. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第八天】(solr服务器搭建、搜索功能实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  9. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第七天】(redis缓存)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

随机推荐

  1. 分享一个php加密字符串类。

    class base64{ /** * 加密字符串 * @access static * @param string $data 字符串 * @param string $key 加密key * @r ...

  2. Web.config中executionTimeout的单位

    executionTimeout:表示允许执行请求的最大时间限制,单位为秒

  3. 学术Essay写作如何体现逻辑的应用

    作为一篇学术essay,逻辑要求是必不可少的.那么,学术essay如何写作才能体现逻辑呢?这就需要从语言逻辑和科学逻辑出发. 语言逻辑指的是三C原则:(1)complete(完整),(2)concis ...

  4. Linux基础操作及概念

    Linux基础操作及概念 终端的概念 通常我们在使用 Linux 时,并不是直接与系统打交道,而是通过一个叫做 Shell 的中间程序来完成的,在图形界面下为了实现让我们在一个窗口中完成用户输入和显示 ...

  5. SOA--基于银行系统实例分析

    阅读以下关于 Web 系统设计的叙述 [说明] 某银行拟将以分行为主体的银行信息系统,全面整合为由总行统一管理维护的银行信息系统,实现统一的用户账户管理.转账汇款.自助缴费.理财投资.贷款管理.网上支 ...

  6. HDU - 1200 To and Fro

    题意:给定一个,其实是由一个图按蛇形输出而成的字符串,要求按从左到右,从上到下的顺序输出这个图. 分析: 1.把字符串转化成图 2.按要求输出图= = #include<cstdio> # ...

  7. 自定义 radio 的样式,更改选中样式

      思路: 1. 可以为<label>元素添加生成性内容(伪元素),并基于单选按钮的状态来为其设置样式: 2. 然后把真正的单选按钮隐藏起来: 3. 最后把生成内容美化一下. 解决方法: ...

  8. oracle常用密令大全

    1.create user username identified by password;//建用户名和密码oracle ,oracle 2.grant connect,resource,dba t ...

  9. 剑指offer题目汇总

    二维数组中的查找 题目:在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中 ...

  10. SpringMVC使用可以访问静态资源,但是导致Controller访问失败

    如果在web.xml 拦截配置如下: <!-- Spring MVC servlet --> <servlet> <servlet-name>SpringMVC&l ...