淘淘商城第二天笔记Word文档下载推荐.docx
- 文档编号:18165036
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:25
- 大小:806.38KB
淘淘商城第二天笔记Word文档下载推荐.docx
《淘淘商城第二天笔记Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《淘淘商城第二天笔记Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。
3、把mapper的代理对象放到spring容器中。
使用扫描包的方式加载mapper的代理对象。
Service层
1、事务管理
2、需要把service实现类对象放到spring容器中管理。
表现层
1、配置注解驱动
2、配置视图解析器
3、需要扫描controller
Web.xml
1、spring容器的配置
2、Springmvc前端控制器的配置
3、Post乱码过滤器
框架整合
需要把配置文件放到taotao-manager-web工程下。
因为此工程为war工程,其他的工程只是一个jar包。
Mybatis整合
<
?
xmlversion="
1.0"
encoding="
UTF-8"
?
>
!
DOCTYPEconfiguration
PUBLIC"
-//mybatis.org//DTDConfig3.0//EN"
"
http:
//mybatis.org/dtd/mybatis-3-config.dtd"
configuration>
/configuration>
applicationContext-dao.xml
beansxmlns="
//www.springframework.org/schema/beans"
xmlns:
context="
//www.springframework.org/schema/context"
p="
//www.springframework.org/schema/p"
aop="
//www.springframework.org/schema/aop"
tx="
//www.springframework.org/schema/tx"
xsi="
//www.w3.org/2001/XMLSchema-instance"
xsi:
schemaLocation="
//www.springframework.org/schema/beanshttp:
//www.springframework.org/schema/beans/spring-beans-4.0.xsd
http:
//www.springframework.org/schema/contexthttp:
//www.springframework.org/schema/context/spring-context-4.0.xsd
//www.springframework.org/schema/aophttp:
//www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp:
//www.springframework.org/schema/txhttp:
//www.springframework.org/schema/tx/spring-tx-4.0.xsd
//www.springframework.org/schema/utilhttp:
//www.springframework.org/schema/util/spring-util-4.0.xsd"
<
--数据库连接池-->
--加载配置文件-->
context:
property-placeholderlocation="
classpath:
resource/db.properties"
/>
beanid="
dataSource"
class="
com.alibaba.druid.pool.DruidDataSource"
destroy-method="
close"
<
propertyname="
url"
value="
${jdbc.url}"
username"
${jdbc.username}"
password"
${jdbc.password}"
driverClassName"
${jdbc.driver}"
maxActive"
10"
minIdle"
5"
/bean>
--配置sqlsessionFactory-->
sqlSessionFactory"
org.mybatis.spring.SqlSessionFactoryBean"
configLocation"
mybatis/SqlMapConfig.xml"
/property>
ref="
--配置扫描包,加载mapper代理对象-->
beanclass="
org.mybatis.spring.mapper.MapperScannerConfigurer"
basePackage"
com.taotao.mapper"
/beans>
applicationContext-service.xml
--扫描包加载Service实现类-->
component-scanbase-package="
com.taotao.service"
/context:
component-scan>
applicationContext-trans.xml
--事务管理器-->
transactionManager"
class="
org.springframework.jdbc.datasource.DataSourceTransactionManager"
--数据源-->
--通知-->
tx:
adviceid="
txAdvice"
transaction-manager="
attributes>
<
--传播行为-->
methodname="
save*"
propagation="
REQUIRED"
insert*"
add*"
create*"
delete*"
update*"
find*"
SUPPORTS"
read-only="
true"
select*"
get*"
/tx:
advice>
--切面-->
aop:
config>
advisoradvice-ref="
pointcut="
execution(*com.taotao.service.*.*(..))"
/aop:
mvc="
//www.springframework.org/schema/mvc"
//www.springframework.org/schema/beans/spring-beans.xsd
//www.springframework.org/schema/mvchttp:
//www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
//www.springframework.org/schema/context/spring-context.xsd"
com.taotao.controller"
mvc:
annotation-driven/>
bean
org.springframework.web.servlet.view.InternalResourceViewResolver"
prefix"
/WEB-INF/jsp/"
suffix"
.jsp"
web-appxmlns:
xmlns="
web="
id="
taotao"
version="
2.5"
display-name>
taotao-manager<
/display-name>
welcome-file-list>
welcome-file>
index.html<
/welcome-file>
index.htm<
index.jsp<
default.html<
default.htm<
default.jsp<
/welcome-file-list>
--加载spring容器-->
context-param>
param-name>
contextConfigLocation<
/param-name>
param-value>
spring/applicationContext-*.xml<
/param-value>
/context-param>
listener>
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
/listener>
--解决post乱码-->
filter>
filter-name>
CharacterEncodingFilter<
/filter-name>
filter-class>
org.springframework.web.filter.CharacterEncodingFilter<
/filter-class>
init-param>
encoding<
utf-8<
/init-param>
/filter>
filter-mapping>
url-pattern>
/*<
/url-pattern>
/filter-mapping>
--springmvc的前端控制器-->
servlet>
servlet-name>
/servlet-name>
servlet-class>
org.springframework.web.servlet.DispatcherServlet<
/servlet-class>
--contextConfigLocation不是必须的,如果不配置contextConfigLocation,springmvc的配置文件默认在:
WEB-INF/servlet的name+"
-servlet.xml"
-->
spring/springmvc.xml<
load-on-startup>
1<
/load-on-startup>
/servlet>
servlet-mapping>
/<
/servlet-mapping>
/web-app>
/:
会拦截所有请求包括静态资源。
需要在springmvc.xml中添加静态资源的映射。
--资源映射-->
resourceslocation="
/WEB-INF/css/"
mapping="
/css/**"
/>
/WEB-INF/js/"
/js/**"
添加静态资源
Springmvc和spring的父子容器关系
Springmvc
Controller
子容器可以访问父容器中的对象。
Spring容器
controller
Service
Dao
父容器不能访问子容器对象。
例如:
在applicationContext-service中配置:
com.taotao"
会扫描@Controller、@Service、@Repository、@Compnent
Springmvc。
Xml中不扫描。
结论:
springmvc。
不能提供服务,因为springmvc子容器中没有controller对象。
测试整合结果
需求
跟据商品id查询商品信息。
Sql语句
SELECT*fromtb_itemWHEREid=536563
可以使用逆向工程生成的mapper文件。
接收商品id调用dao查询商品信息。
返回商品pojo对象。
/**
*商品管理Service
*<
p>
Title:
ItemServiceImpl<
/p>
Description:
Company:
*@author入云龙
*@date2015年9月2日上午10:
47:
14
*@version1.0
*/
@Service
publicc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 淘淘 商城 第二 笔记
![提示](https://static.bdocx.com/images/bang_tan.gif)