Java之SSH项目:网络商城-项目+源代码 day02(服务中间件Dubbo连接方式,MyBatis,Mapper

c、applicationContext-dao.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

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-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

<context:property-placeholder location=“classpath:properties/*.properties” />

<bean id=“dataSource” class=“com.alibaba.druid.pool.DruidDataSource”

destroy-method=“close”>

d、dao当中定义包

在这里插入图片描述

e、dao当中定义资源文件bd.properties

在这里插入图片描述

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8

jdbc.username=root

jdbc.password=root

五、service整合


1、创建配置文件

a、applicationContext-service.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo” 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-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

创建包结构taotao-manager-interface当中创建com.taotao.service

在这里插入图片描述

b、applicationContext-transaction.xml

在这里插入图片描述

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

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-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

<bean id=“transactionManager”

class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>

<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>

tx:attributes

<tx:method name=“save*” propagation=“REQUIRED” />

<tx:method name=“insert*” propagation=“REQUIRED” />

<tx:method name=“add*” propagation=“REQUIRED” />

<tx:method name=“create*” propagation=“REQUIRED” />

<tx:method name=“delete*” propagation=“REQUIRED” />

<tx:method name=“update*” propagation=“REQUIRED” />

<tx:method name=“find*” propagation=“SUPPORTS” read-only=“true” />

<tx:method name=“select*” propagation=“SUPPORTS” read-only=“true” />

<tx:method name=“get*” propagation=“SUPPORTS” read-only=“true” />

</tx:attributes>

</tx:advice>

aop:config

<aop:advisor advice-ref=“txAdvice”

pointcut=“execution(* com.taotao.service..(…))” />

</aop:config>

c、配置web.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns=“http://java.sun.com/xml/ns/javaee”

xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”

version=“2.5”>

taotao-manager-service

index.html

index.htm

index.jsp

default.html

default.htm

default.jsp

contextConfigLocation

classpath:spring/applicationContext-*.xml

org.springframework.web.context.ContextLoaderListener

六、表现层搭建


1、相关配置文件

在这里插入图片描述

springmvc.xml

在这里插入图片描述

<?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:p=“http://www.springframework.org/schema/p”

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”

xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd

http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<context:component-scan

base-package=“com.taotao.controller” />

<mvc:annotation-driven />

<bean

class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>

创建对应的包结构

在这里插入图片描述

创建对应的jsp文件夹

在这里插入图片描述

在这里插入图片描述

在WEB-INF当中配置Servlet

2、dao层创建对应的接口对应的映射文件

a、创建对应的接口

在这里插入图片描述

package com.taotao.mapper;

/*

  • 测试接口查询当前的时间

*/

public interface TestMapper {

public String queryNow();

}

b、创建对应的接口的映射文件TestMapper.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8" ?>

select NOW()

3、interface层创建对应的接口对应的映射文件

在这里插入图片描述

package com.taotao.service;

/*

  • 测试接口查询当前的时间

*/

public interface TestService {

public String queryNow();

}

4、service层TestServiceImpl实现TestService接口

在这里插入图片描述

package com.taotao.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.taotao.mapper.TestMapper;

import com.taotao.service.TestService;

@Service

public class TestServiceImpl implements TestService {

@Autowired

private TestMapper mapper;

@Override

public String queryNow() {

// 1.注入mapper

// 2、调用mapper方法返回

return mapper.queryNow();

}

}

七、发布服务


1、配置dubbo

在这里插入图片描述

<dubbo:application name=“taotao-manager” />

<dubbo:registry protocol=“zookeeper” address=“192.168.25.128:2181” />

<dubbo:protocol name=“dubbo” port=“20880” />

<dubbo:service interface=“com.taotao.service.TestService” ref=“testServiceImpl” />

2、applicationContext-service.xml

在这里插入图片描述

<dubbo:application name=“taotao-manager” />

<dubbo:registry protocol=“zookeeper” address=“115.159.79.135:2181” />

<dubbo:protocol name=“dubbo” port=“20880” />

<dubbo:service interface=“com.taotao.service.TestService” ref=“testServiceImpl” />

3、创建控制层相关内容

a、springmvc.xml

<?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:p=“http://www.springframework.org/schema/p”

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”

xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd

http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<context:component-scan

base-package=“com.taotao.controller” />

<mvc:annotation-driven />

<bean

class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>

<dubbo:application name=“taotao-manager-web”/>

<dubbo:registry protocol=“zookeeper” address=“192.168.25.128:2181”/>

<dubbo:reference interface=“com.taotao.service.TestService” id=“testService” />

b、创建TestController

在这里插入图片描述

在这里插入图片描述

启动服务的消费者

在这里插入图片描述

访问项目

http://localhost:8081/test/queryNow

在这里插入图片描述

运行报错

在这里插入图片描述

没有找到对应的类

在这里插入图片描述

在taotao-manager-dao\pom.xml当中配置一个插件

在这里插入图片描述

src/main/java

**/*.properties

**/*.xml

false

改好后需要选择taotao-manager-dao工程执行

run as maven install

在这里插入图片描述

八、商品列表查询


(一)显示后台页面

1、引入逆向工程

逆向工程下载地址和页面下载:

链接: https://pan.baidu.com/s/1W2s0mNdEr5G-D-_WwmSztw 提取码: 3y73

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2、运行逆向工程

在这里插入图片描述

生成对应的文件

在这里插入图片描述

在这里插入图片描述

3、将生成的内容拷贝到当前自己的工程当中

在这里插入图片描述

在这里插入图片描述

4、引入页面

放置在WEB-INF当中

页面代码下载地址:

链接: https://pan.baidu.com/s/1BuzcPiNd0E1_urtmHCvJjw 提取码: 18u4

在这里插入图片描述

5、资源映射的配置

由于在web.xml中定义的url拦截形式为“/”表示拦截所有的url请求,包括静态资源例如css、js等。

所以需要在springmvc.xml中添加资源映射标签:

在这里插入图片描述

<mvc:resources location=“/WEB-INF/js/” mapping=“/js/**”/>

<mvc:resources location=“/WEB-INF/css/” mapping=“/css/**”/>

6、创建控制层PageController

在这里插入图片描述

package com.taotao.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

/*

  • 显示页面

*/

@Controller

public class PageController {

@RequestMapping(“/”)

public String showIndex() {

return “index”;

}

}

在这里插入图片描述

删除创建web的时候自动生成的index.jsp

在这里插入图片描述

7、运行项目

在这里插入图片描述

8、访问项目

http://localhost:8081/

在这里插入图片描述

(二)显示商品列表

1、在PageController当中添加showPage方法

在这里插入图片描述

//显示商品的查询的页面

//url:item-list

@RequestMapping(“/{page}”)

public String showPage(@PathVariable String page) {//@PathVariable表示从URL拦截

return page;

}

2、再次运行项目

http://localhost:8081/

在这里插入图片描述

在这里插入图片描述

3、使用PageHelper实现分页功能

下载地址链接: https://pan.baidu.com/s/1BwYokfOKugVm3mpuz4-q8w 提取码: pbme

引入插件源代码

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

将导入的工程安装到本地,形式自己的maven工程

在这里插入图片描述

dao当中引入

在这里插入图片描述

4、使用PageHelper在Mybatis的全局文件中配置SqlMapConfig.xml中配置拦截器插件:

在这里插入图片描述

5、设置分页信息

编写测试代码

在这里插入图片描述

创建对应的类

在这里插入图片描述

在这里插入图片描述

package com.taotao.test.pagehelp;

import java.util.List;

import org.junit.Test;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.github.pagehelper.PageHelper;

import com.github.pagehelper.PageInfo;

import com.taotao.mapper.TbItemMapper;

import com.taotao.pojo.TbItem;

import com.taotao.pojo.TbItemExample;

public class TestPageHelper {

@Test

public void testhelper() {

//2、初始化spring容器

ApplicationContext context = new ClassPathXmlApplicationContext(“classpath:spring/applicationContext-dao.xml”);

//3、获取mapper的代理对象

TbItemMapper itemMapper = context.getBean(TbItemMapper.class);

//1、设置分页信息

PageHelper.startPage(1, 3);//3行 紧跟着的第一个查询才会被分页

//4、调用mapper符方法查询数据

TbItemExample example = new TbItemExample();//设置查询条件使用

List list = itemMapper.selectByExample(example);//select * from tb_item;

List list2 = itemMapper.selectByExample(example);//select * from tb_item;

//取分页信息

PageInfo info = new PageInfo(list);

System.out.println(“第一个分页的list的集合的长度:”+list.size());

//for (TbItem tbItem : list) {

// System.out.println(tbItem.getId()+"名称 " + tbItem.getTitle());

//}

System.out.println(“第二个分页的list的集合的长度:”+list2.size());

//5、遍历结果集 打印

System.out.println(“查询的总记录数:”+info.getTotal());

//for (TbItem tbItem : list2) {

// System.out.println(tbItem.getId()+"名称 " + tbItem.getTitle());

//}

}

}

运行结果

在这里插入图片描述

(三)Service

1、参数:int page ,int rows,业务逻辑:查询所有商品列表,要进行分页处理。返回值:EasyUIDataGridResult

在这里插入图片描述

在这里插入图片描述

package com.taotao.common.pojo;

import java.io.Serializable;

import java.util.List;

/*

  • datagrid展示数据的POJO,包括商品的POJO

*/

public class EasyUIDataGridResult implements Serializable {

private Integer total;

private List rows;

public EasyUIDataGridResult() {

}

public EasyUIDataGridResult(Integer total, List rows) {

super();

this.total = total;

this.rows = rows;

}

public Integer getTotal() {

return total;

}

public void setTotal(Integer total) {

this.total = total;

}

public List getRows() {

return rows;

最后

分享一套我整理的面试干货,这份文档结合了我多年的面试官经验,站在面试官的角度来告诉你,面试官提的那些问题他最想听到你给他的回答是什么,分享出来帮助那些对前途感到迷茫的朋友。

面试经验技巧篇
  • 经验技巧1 如何巧妙地回答面试官的问题
  • 经验技巧2 如何回答技术性的问题
  • 经验技巧3 如何回答非技术性问题
  • 经验技巧4 如何回答快速估算类问题
  • 经验技巧5 如何回答算法设计问题
  • 经验技巧6 如何回答系统设计题
  • 经验技巧7 如何解决求职中的时间冲突问题
  • 经验技巧8 如果面试问题曾经遇见过,是否要告知面试官
  • 经验技巧9 在被企业拒绝后是否可以再申请
  • 经验技巧10 如何应对自己不会回答的问题
  • 经验技巧11 如何应对面试官的“激将法”语言
  • 经验技巧12 如何处理与面试官持不同观点这个问题
  • 经验技巧13 什么是职场暗语

面试真题篇
  • 真题详解1 某知名互联网下载服务提供商软件工程师笔试题
  • 真题详解2 某知名社交平台软件工程师笔试题
  • 真题详解3 某知名安全软件服务提供商软件工程师笔试题
  • 真题详解4 某知名互联网金融企业软件工程师笔试题
  • 真题详解5 某知名搜索引擎提供商软件工程师笔试题
  • 真题详解6 某初创公司软件工程师笔试题
  • 真题详解7 某知名游戏软件开发公司软件工程师笔试题
  • 真题详解8 某知名电子商务公司软件工程师笔试题
  • 真题详解9 某顶级生活消费类网站软件工程师笔试题
  • 真题详解10 某知名门户网站软件工程师笔试题
  • 真题详解11 某知名互联网金融企业软件工程师笔试题
  • 真题详解12 国内某知名网络设备提供商软件工程师笔试题
  • 真题详解13 国内某顶级手机制造商软件工程师笔试题
  • 真题详解14 某顶级大数据综合服务提供商软件工程师笔试题
  • 真题详解15 某著名社交类上市公司软件工程师笔试题
  • 真题详解16 某知名互联网公司软件工程师笔试题
  • 真题详解17 某知名网络安全公司校园招聘技术类笔试题
  • 真题详解18 某知名互联网游戏公司校园招聘运维开发岗笔试题

资料整理不易,点个关注再走吧

blic Integer getTotal() {

return total;

}

public void setTotal(Integer total) {

this.total = total;

}

public List getRows() {

return rows;

最后

分享一套我整理的面试干货,这份文档结合了我多年的面试官经验,站在面试官的角度来告诉你,面试官提的那些问题他最想听到你给他的回答是什么,分享出来帮助那些对前途感到迷茫的朋友。

面试经验技巧篇
  • 经验技巧1 如何巧妙地回答面试官的问题
  • 经验技巧2 如何回答技术性的问题
  • 经验技巧3 如何回答非技术性问题
  • 经验技巧4 如何回答快速估算类问题
  • 经验技巧5 如何回答算法设计问题
  • 经验技巧6 如何回答系统设计题
  • 经验技巧7 如何解决求职中的时间冲突问题
  • 经验技巧8 如果面试问题曾经遇见过,是否要告知面试官
  • 经验技巧9 在被企业拒绝后是否可以再申请
  • 经验技巧10 如何应对自己不会回答的问题
  • 经验技巧11 如何应对面试官的“激将法”语言
  • 经验技巧12 如何处理与面试官持不同观点这个问题
  • 经验技巧13 什么是职场暗语

[外链图片转存中…(img-iJmkKanE-1714338513345)]

面试真题篇
  • 真题详解1 某知名互联网下载服务提供商软件工程师笔试题
  • 真题详解2 某知名社交平台软件工程师笔试题
  • 真题详解3 某知名安全软件服务提供商软件工程师笔试题
  • 真题详解4 某知名互联网金融企业软件工程师笔试题
  • 真题详解5 某知名搜索引擎提供商软件工程师笔试题
  • 真题详解6 某初创公司软件工程师笔试题
  • 真题详解7 某知名游戏软件开发公司软件工程师笔试题
  • 真题详解8 某知名电子商务公司软件工程师笔试题
  • 真题详解9 某顶级生活消费类网站软件工程师笔试题
  • 真题详解10 某知名门户网站软件工程师笔试题
  • 真题详解11 某知名互联网金融企业软件工程师笔试题
  • 真题详解12 国内某知名网络设备提供商软件工程师笔试题
  • 真题详解13 国内某顶级手机制造商软件工程师笔试题
  • 真题详解14 某顶级大数据综合服务提供商软件工程师笔试题
  • 真题详解15 某著名社交类上市公司软件工程师笔试题
  • 真题详解16 某知名互联网公司软件工程师笔试题
  • 真题详解17 某知名网络安全公司校园招聘技术类笔试题
  • 真题详解18 某知名互联网游戏公司校园招聘运维开发岗笔试题

[外链图片转存中…(img-LKsCPnea-1714338513345)]

资料整理不易,点个关注再走吧

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 14
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值