Spring例子JPetStore分析---------3jpetstore的各层之间的关系部分分析

基于MVC的jpetstore项目分析 jpetstore为博主 大二下 软件开发架构平台技术 的一项实验内容。 下面是基于MVC的jpetstore项目分析:jpetstore: github地址:https://github.com/SwordHarry/Jpetstore 使用环境:IntelliJ IDEA 开发架构:MVC 数据库连接:JDBC 一、准备工作 创建项目,选择为java web项目 输... 阅读详情

下面就jpetstore的账号管理部分,来分析一下jpetstore的各层之间的关系:

1。持久层分析

1.1账号管理的iBatis的xml影射部分如下:

账号管理涉及到四张表:

signon 存放用户名,密码

account, 存放用户的基本信息

 profile,  存放用户选择的语言,以及喜爱的商品分类

 bannerdata 目前不清楚

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Account">

《账号信息结果集》

  <resultMap id="result" class="org.springframework.samples.jpetstore.domain.Account">
    <result property="username" column="userid" columnIndex="1"/>
    <result property="email" column="email" columnIndex="2"/>
    <result property="firstName" column="firstname" columnIndex="3"/>
    <result property="lastName" column="lastname" columnIndex="4"/>
    <result property="status" column="status" columnIndex="5"/>
    <result property="address1" column="addr1" columnIndex="6"/>
    <result property="address2" column="addr2" columnIndex="7"/>
    <result property="city" column="city" columnIndex="8"/>
    <result property="state" column="state" columnIndex="9"/>
    <result property="zip" column="zip" columnIndex="10"/>
    <result property="country" column="country" columnIndex="11"/>
    <result property="phone" column="phone" columnIndex="12"/>
    <result property="languagePreference" column="langpref" columnIndex="13"/>
    <result property="favouriteCategoryId" column="favcategory" columnIndex="14"/>
    <result property="listOption" column="mylistopt" columnIndex="15"/>
    <result property="bannerOption" column="banneropt" columnIndex="16"/>
    <result property="bannerName" column="bannername" columnIndex="17"/>
  </resultMap>

《根据用户名,获得用户信息》

  <select id="getAccountByUsername" resultMap="result">
    select
          signon.username as userid,
          account.email,
          account.firstname,
          account.lastname,
          account.status,
          account.addr1,
          account.addr2,
          account.city,
          account.state,
          account.zip,
          account.country,
          account.phone,
          profile.langpref,
          profile.favcategory,
          profile.mylistopt,
          profile.banneropt,
          bannerdata.bannername
    from account, profile, signon, bannerdata
    where account.userid = #value#
      and signon.username = account.userid
      and profile.userid = account.userid
      and profile.favcategory = bannerdata.favcategory
  </select>

《根据账号,密码,获取账号》

  <select id="getAccountByUsernameAndPassword" resultMap="result">
    select
      signon.username as userid,
      account.email,
      account.firstname,
      account.lastname,
      account.status,
      account.addr1,
      account.addr2,
      account.city,
      account.state,
      account.zip,
      account.country,
      account.phone,
      profile.langpref,
      profile.favcategory,
      profile.mylistopt,
      profile.banneropt,
      bannerdata.bannername
    from account, profile, signon, bannerdata
    where account.userid = #username#
      and signon.password = #password#
      and signon.username = account.userid
      and profile.userid = account.userid
      and profile.favcategory = bannerdata.favcategory
  </select>

《获取系统用户名列表》

  <select id="getUsernameList" resultClass="java.lang.String">
    select username as value from signon
  </select>

《更新账号信息》

  <update id="updateAccount">
    update account set email = #email#, firstname = #firstName#, lastname = #lastName#, status = #status#, addr1 = #address1#, addr2 = #address2:varchar#, city = #city#, state = #state#, zip = #zip#, country = #country#, phone = #phone# where userid = #username#
  </update>

《增加新账号》

  <insert id="insertAccount">
    insert into account (email, firstname, lastname, status, addr1, addr2, city, state, zip, country, phone, userid) values (#email#, #firstName#, #lastName#, #status#, #address1#, #address2:varchar#, #city#, #state#, #zip#, #country#, #phone#, #username#)
  </insert>

《更新用户profile表,其中包括用户语言选择,以及喜欢的动物分类

  <update id="updateProfile">
    update profile set langpref = #languagePreference#, favcategory = #favouriteCategoryId#, mylistopt = #listOptionAsInt#, banneropt = #bannerOptionAsInt# where userid = #username#
  </update>

《增加用户profile信息〉

  <insert id="insertProfile">
    insert into profile (langpref, favcategory, mylistopt, banneropt, userid) values (#languagePreference#, #favouriteCategoryId#, #listOptionAsInt#, #bannerOptionAsInt#, #username#)
  </insert>

〈更新用户密码〉

  <update id="updateSignon">
    update signon set password = #password# where username = #username#
  </update>

〈增加用户名,密码到用户登录表Signon〉

  <insert id="insertSignon">
    insert into signon (password,username) values (#password#,#username#)
  </insert>

</sqlMap>
1.2  Account为账号管理的POJO类,AccountDao 为账号管理interface,规定了一系列方法:

public interface AccountDao {

  Account getAccount(String username) throws DataAccessException;

  Account getAccount(String username, String password) throws DataAccessException;

  void insertAccount(Account account) throws DataAccessException;

  void updateAccount(Account account) throws DataAccessException;

 List getUsernameList() throws DataAccessException;

}

1.3Account interface 实现:

public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {

  public Account getAccount(String username) throws DataAccessException {
    return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsername", username);
  }

根据用户名,密码,获得账号

  public Account getAccount(String username, String password) throws DataAccessException {
    Account account = new Account();
    account.setUsername(username);
    account.setPassword(password);
    return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsernameAndPassword", account);
  }

创建账号,需要更新account,signon,profile三张表

  public void insertAccount(Account account) throws DataAccessException {
    getSqlMapClientTemplate().insert("insertAccount", account);
    getSqlMapClientTemplate().insert("insertProfile", account);
    getSqlMapClientTemplate().insert("insertSignon", account);
  }

更新账号,需要更新account,signon,profile三张表

  public void updateAccount(Account account) throws DataAccessException {
    getSqlMapClientTemplate().update("updateAccount", account, 1);
    getSqlMapClientTemplate().update("updateProfile", account, 1);
    if (account.getPassword() != null && account.getPassword().length() > 0) {
      getSqlMapClientTemplate().update("updateSignon", account, 1);
    }
  }

《获取系统用户名列表》
 
 public List getUsernameList() throws DataAccessException {
  return getSqlMapClientTemplate().queryForList("getUsernameList", null);
 }

}

总结:

iBatis持久层使用sql-map-config.xml配置所有ibatis .xml文件

<sqlMapConfig>

 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Account.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Category.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Product.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Item.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Order.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/LineItem.xml"/>
 <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml"/>

</sqlMapConfig>

使用dataAccessContext-config.xml配置所有DAO实现

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="WEB-INF/sql-map-config.xml"/>
  <property name="dataSource" ref="dataSource"/>
 </bean>

 <bean id="accountDao" class="org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao">
  <property name="sqlMapClient" ref="sqlMapClient"/>
 </bean>

2,持久层和业务逻辑层的耦合,业务逻辑接口中包含了AccountDAO的接口操作

public interface PetStoreFacade {

 Account getAccount(String username);

 Account getAccount(String username, String password);

 void insertAccount(Account account);

 void updateAccount(Account account);

 List getUsernameList();

。。。。。。。

}

业务逻辑对象PetStoreImpl 实现了对accountDao的再次封装

public class PetStoreImpl implements PetStoreFacade, OrderService {

 private AccountDao accountDao;

public Account getAccount(String username) {
  return this.accountDao.getAccount(username);
 }

 public Account getAccount(String username, String password) {
  return this.accountDao.getAccount(username, password);
 }

 public void insertAccount(Account account) {
  this.accountDao.insertAccount(account);
 }

 public void updateAccount(Account account) {
  this.accountDao.updateAccount(account);
 }

 public List getUsernameList() {
  return this.accountDao.getUsernameList();
 }

。。。。

}

总结:

持久层与业务逻辑层的耦合是在applicationContext.cml中:

为业务逻辑层提供事务管理


<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
  <property name="transactionManager"><ref bean="transactionManager"/></property>
  <property name="transactionAttributes">
   <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>

 
 <bean id="petStore" parent="baseTransactionProxy">
  <property name="target">
   <bean class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl">
    <property name="accountDao" ref="accountDao"/>
    <property name="categoryDao" ref="categoryDao"/>
    <property name="productDao" ref="productDao"/>
    <property name="itemDao" ref="itemDao"/>
    <property name="orderDao" ref="orderDao"/>
   </bean>
  </property>

4表示层和业务逻辑层的耦合:

表示层和业务逻辑层的耦合是通过BaseAction来实现的,并通过接口来访问业务逻辑对象:

public abstract class BaseAction extends Action {

  private PetStoreFacade petStore;

 public void setServlet(ActionServlet actionServlet) {
  super.setServlet(actionServlet);
  if (actionServlet != null) {
   ServletContext servletContext = actionServlet.getServletContext();
   WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   this.petStore = (PetStoreFacade) wac.getBean("petStore");
  }
 }

 protected PetStoreFacade getPetStore() {
  return petStore;
 }

}

所有的系统里面的Action都是从BaseAction派生过来的,而BaseAction的派生类中,提供了对业务逻辑对象
 PetStoreFacade 的访问。

基于Spring Boot的jpetstore项目分析 将原本MVC架构的jpetstore用Spring Boot重构。 github 地址:https://github.com/SwordHarry/mypetstoreSpringBoot 开发环境:IntelliJ IDEA 集成框架:Spring Boot 前端渲染工具:Thymeleaf ORM框架:Mybatis 在此基本要求上实现的额外功能: 1.添加验证码功能:在... 阅读详情

相关推荐

使用Struts+Spring+Hibernate构建jpetstore实战项目

本文还有配套的精品资源,点击获取 简介:Struts、Spring和Hibernate是Java Web开发中常用的三大框架。本课程将以jpetstore项目为例,详细讲解如何集成这三个框架构建一个完整的MVC架构Web应用程序。涵盖从配置文件管理、实体类设计、数据操作抽象,到服务层逻辑处理以及前端视图展示的完整流程。通过本课程的学习,学员将深入理解框架的协同工作原理,并能...

weixin_28888459的博客 1436

从零开始-实现JpetStore网站-1-建立项目框架以及项目介绍

从零开始-实现JpetStore网站-1-建立项目框架以及项目介绍

chenyaqun的博客 797

Java Pet Store源代码剖析与实践

本文还有配套的精品资源,点击获取 简介:jpetstore是一个开源项目,旨在演示Java Web应用的开发技术。该项目包含了全部源代码、数据库文件以及运行环境,适用于学习Java编程、MVC架构、Java EE技术等。通过分析该源代码,开发者可以掌握从代码编写到环境部署的完整流程。 1. Java编程技术实践 在当今的IT行业中,Java编程语言凭借其跨平...

weixin_36382073的博客 906

java各层之间的关系_Spring例子JPetStore分析---------3jpetstore的各层之间的关系部分分析...

下面就jpetstore的账号管理部分,来分析一下jpetstore的各层之间的关系:1。持久层分析1.1账号管理的iBatis的xml影射部分如下:账号管理涉及到四张表:signon 存放用户名,密码account, 存放用户的基本信息profile, 存放用户选择的语言,以及喜爱的商品分类bannerdata 目前不清楚《账号信息结果集》《根据用户名,获得用户信息》selectsignon....

weixin_31792645的博客 148

jpetstore宠物店程序深度解析与实战演练

本文还有配套的精品资源,点击获取 简介:jpetstore是一个示例项目,用于展示如何运用Java技术栈和MVC模式构建Web应用。本项目深入讲解了Struts和Spring框架的应用,包括HTTP请求处理、业务逻辑流转、依赖注入、面向切面编程、事务管理等。还涉及数据库集成,使用MySQL存储数据,并介绍如何配置Tomcat服务器部署应用。开发者通过操作此项目能够学习到We...

weixin_42376614的博客 1453

JPetStoreDemo

MyBatis JPetStore JPetStore 6 是一个完整的 Web 应用程序,构建在 MyBatis 3、Spring 3 和 Stripes 之上。 它可以在 MyBatis 项目站点的下载部分下载。 在本节中,我们将遍历此示例以了解它是如何构建的并学习如何运行它。 见: : 使用 Tomcat 7 运行 在 Tomcat 7 下运行 JPetStore 示例(使用 maven)。 克隆这个仓库 打开命令提示符/shell 并更改为克隆目录 发出以下命令以使用 Tomcat 7 运行项目 mvn clean tomcat7:run 在浏览器中运行应用程序 按 Ctrl-C 停止服务器。

基于struts+spring+ibatis的 J2EE 开发(jpetstore分析)

1. 前言Struts 是目前Java Web MVC框架中不争的王者。经过长达五年的发展,Struts已经逐渐成长为一个稳定、成熟的框架,并且占有了MVC框架中最大的市场份额。但是Struts某些技术特性上已经落后于新兴的MVC框架。面对Spring MVC、Webwork2 这些设计更精密,扩展性更强的框架,Struts受到了前所未有的挑战。但站在产品开发的角度而言,Struts仍然是最稳妥的

蒋剑锋的专栏-java技术 1746

jpetstore

由sun公司研发的jpetstore web应用系统,是一个卖宠物的网站,有Java语言编写,是一个开源的helloworld似得web应用系统!

jpetstore-Spring Boot-Thymeleaf

本博客主要针对基于SpringBoot集成的jpetstore中的前端渲染引擎Thymeleaf进行分析。 在html文件内是无法使用jsp标签的,为了实现类似于jsp标签的功能,这里博主使用到了Thymeleaf前端渲染引擎。它能实现jsp标签的功能,并且可以做到前后端的解耦合。 一、准备工作 首先创建项目工程时就要选择Spring初始化工具,让IntelliJ为我们做好初始化工作。 ...

一把健 525

springMVC自带的jpetstore源码

springMVC自带的jpetstore源码,没有经过任何修改,可以根据自己的需要做调整

傅里叶光学(1)

傅里叶光学,可以看作是通信理论中傅里叶变换等一系列数学思想以及系统理论与光学(主要是衍射光学)相结合的产物关于傅里叶光学的应用领域,本节介绍了成像,当然事实上不可能仅限于成像,经典的还如激光散斑的一些应用,干涉计量,还有傅里叶变换光谱学等等。最后总结一下,傅里叶光学我认为可以看做一个工具,对于任意的系统,它能给出一些数学思想与物理原理进行解释和分析,找出系统的扰动和响应的关系,或者说根据扰动和响应,来研究或者设计一个系统。

m0_53607446的博客 1705

spring+ibatis

<br />http://blog.csdn.net/daryl715/archive/2007/08/27/1760793.aspx<br /> <br /> 2.4. 代码剖析<br />  下面就让我们开始进一步分析JpetStore4.0的源代码,为下面的改造铺路。<br />BeanAction.java是唯一一个Struts action类,位于com.ibatis.struts包下。正如上文所言,它是一个通用的控制类,利用反射机制,把控制转移到form bean的某个方法来处理。具体处理过程参

325

矩形阱粒子能级求解方法

问题10. 考虑粒子在“矩形阱”中的能级:−uxx+Vu=λu -u_{xx} + V u = \lambda u −uxx​+Vu=λu其中 V(x)={−H∣x∣≤L,0∣x∣>L. V(x) = \begin{cases} -H & |x| \leq L, \\ 0 & |x| > L. \end{cases} V(x)={−H0​∣x∣≤L,∣x∣>L.​提示:在 ∣x∣<L |x| < L ∣x∣<L 和 ∣x∣>L |x| > L ∣x∣>L 的区域分别求解方程,解必须在 ∣x∣=L |x|

weixin_30777913的博客 929

探索MyBatis JPetStore 6:一个现代的Java Web示例应用

是MyBatis团队提供的一个开源项目,它是一个基于Spring Boot和MyBatis框架的完整Web应用程序示例。这个项目旨在展示如何有效地将这些流行的技术整合在一起,以构建高性能、易于维护的数据驱动的应用程序。 ## 项目简介 JPetStore 6是一个在线宠物商店,提供浏览商品、添加到购物车、结账等基本功能。它是MyBatis 3.5及更高版本的完美示例,展示了如何使用MyBati

gitblog_00031的博客 576

EDA虚拟机分享2020版本(Synopsys2020)

EDA虚拟机分享

亦安的数字小站 9224

SAP项目结算核心:结果分析码配置与KKA2/CJ88排错实战

结果分析码(RA Key)是SAP CO模块中实现项目收入确认与成本分摊的核心机制,其本质是一套融合时间逻辑、价值计算与责任归属的动态规则引擎。它并非简单映射会计科目,而是驱动KKA2和CJ88执行项目实际结算的关键算法,直接影响毛利真实性与财务合规性。在EPC、工程服务及多阶段合同场景下,错误选用RA01等默认配置极易导致收入虚增、税务风险与管理失真。本文结合sap ko88 增强与sap mdvp主数据校验等高频实践痛点,系统解析时间确定方法、值确定方法与结果分析类型三大维度,并提供五层穿透式排查链路,

weixin_34355559的博客 350

stripes + spring mvc + mybatis + mysql运行纪实

基于mybatis提供的jpetstore6.0.1改造,主要是把数据库从hsqldb改为mysql,并且结合spring mvc使用。 有几个要点: 1:Mysql 在src/main/resources下创建Mysql.properties文件,内容如下: jdbc.driverClassName=com.mysql.jdbc.Driver   jdbc.url=jdbc:m

softwarehe的专栏 1366

自动驾驶仿真(五)—— 基于Carsim、Prescan、Simulink的联合仿真

自动驾驶仿真五——基于Carsim、Prescan、Simulink的联合仿真1. 联合仿真流程2. CarSim联合仿真配置要点3. Prescan联合仿真配置要点4. Carsim、Prescan、Simulink联合仿真结果5. 参考学习的书目教材 博主前面的博文已经介绍了Carsim和Prescan各自与Matlab/Simulink的相关联合仿真应用实例,并且论述过几款软件各自的优势及用法,CarSim适合动力学模型的建立,PreScan适合行车场景的搭建,Simulink适合控制算法的设计及信号

zhudj08的博客 1万+

Acegi简介

Acegi安全系统,是一个用于Spring Framework的安全框架,能够和目前流行的Web容器无缝集成。它使用了Spring的方式提供了安全和认证安全服务,包括使用Bean Context,拦截器和面向接口的编程方式。因此,Acegi安全系统能够轻松地适用于复杂的安全需求。 安全涉及到两个不同的概念,认证和授权。前者是关于确认用户是否确实是他们所宣称的身份。授权则是关于确认用...

heweiyabeijing的专栏 551

医学图像处理实战:利用OpenSlide解析病理SVS切片的完整解决方案

本文介绍了使用openslide处理病理SVS切片的完整流程,从基础安装到科研应用。主要内容包括:1)SVS切片特点及openslide工具简介;2)环境配置与软件安装;3)基础操作:读取切片、查看信息、可视化不同层级图像;4)进阶操作:坐标裁剪与批量处理;5)科研方向拓展:结合AI模型进行病理分割分类、量化分析及可视化报告。教程提供了完整的代码示例,帮助毕业设计学生快速掌握病理图像分析的核心技能。

m0_71589036的博客 328

探索激光焊接光束质量诊断系统:原理、应用与前沿

激光焊接光束质量诊断系统是一套专门用于精确评估和监测激光焊接过程中光束特性的精密设备。它宛如一个精密的 “光束医生”,能够全方位地对激光光束进行 “体检”,为焊接工艺提供关键的数据支持。探测器:作为系统的 “感知触角”,探测器负责捕捉激光光束的各种信息,其性能直接影响着诊断的准确性。例如,常见的 CCD(电荷耦合器件)探测器和 CMOS(互补金属氧化物半导体)探测器,它们能够将光信号转化为电信号,具有高灵敏度、高分辨率等特点,可精确探测光束的强度分布、光斑位置等参数。光学透镜。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 2591

spring jpetstore研究入门—完结篇

上一文安装篇讲述了如何把jpetstore导入netbeans工程,现在所有已经准备就绪,接下来就可以开始进入正题了。 首先,我先大概介绍一下jpetstore的整体架构,spring的这个版本主要使用了struts+spring+ibatis的框架组合,而在MVC层的框架,这个版本又同时提供了两个实现版本,一个是struts,一个是spring 自带的web框架,而数据库持久层使用的是...

未知世界 266

Android Telephony主要模块及功能

Telephony的代码主要由五个模块组成 1.Telephony Frameworks 代码区域: frameworks/opt/telephony/ 其中主要的文件在如下目录 /frameworks/opt/telephony/src/java/com/android/internal/telephony/ 其中比较常见的有以下几类文件 1.BaseCommands、RIL构成R

泊客 7741

Jpetstore项目学习笔记(一)

Jpetstore项目学习笔记

aiguoxin 4594

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: Spring例子JPetStore分析---------1
下一篇: Spring例子JPetStore分析---------2
nepper
博客等级 码龄21年 6粉丝 4原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址