(重要 SSM搭建详细步骤)项目一 1 saas项目 powerDesigner(需求分析软件) SSM环境搭建
课程安排Day1-day5 : 练习SSMDay6-day12: 拔高阶段(shiro , dubbo,zookeeper,七牛云存储,poi,webservice,echarts)Day13-day15: pdf报表 , activeMq,svnDay16-day17:实战1. 梳理java技术Css , js,html , jquery , ajaxXml , jsp ...
课程安排
Day1-day5 : 练习SSM
Day6-day12: 拔高阶段(shiro , dubbo,zookeeper,七牛云存储,poi,webservice,echarts)
Day13-day15: pdf报表 , activeMq,svn
Day16-day17:实战
SSM环境搭建的详细步骤
项目阶段用到的技术
1. 梳理java技术
Css , js,html , jquery , ajax
Xml , jsp tomcat
Mysql , jdbc , jdbctemplate
httpServletRequest,httpservletResponse
servlet, filter,listener
redis , linux
web阶段的综合案例
mybatis,spring,springmvc
maven
Adminlte,
PageHelper
Ztree,
Shiro
Dubbo,zookeeper
七牛云存储
Poi报表综合解决方案
PDF报表的解决方案
Webservice
Echarts
ActiveMq
SVN
1.1 项目的学习方式
口才
业务逻辑
技术: 重应用,轻原理,重点应用
2. 云服务的三种模式
2.1 Iaas
Iaas:基础设施即服务
2.2 Paas
Paas: 平台即服务
2.3 Saas
Saas: 软件即服务
2.4 比较
3. 什么是SaaS-Export
3.1 概述
3.2 业务介绍
4. 原型分析与UML用例图
4.1 原型分析
图形化界面的形式展示需求
4.2 UML和用例图
Uml:统一建模语言,以图形化的形式创建模型,展示项目需求
用例图:以图形化方式展示项目的所有模块以及每个模块的参与者
Pd(powerdesigner)
4.3 Saas项目的完整用例图
5. 系统架构与环境搭建
5.1 配置开发环境
Maven配置
Jdk配置:1.8版本
<1>
1.创建 export_parent 父工程(打包方式选择 pom)
删除src目录-在pom文件中带入依赖
2.创建 export_web_manager 子模块(打包方式是 war 包)
3.创建 export_service_system 子模块(打包方式是 jar 包)
4.创建 export_domain 子模块(打包方式是 jar 包)
5.创建 export_dao 子模块(打包方式是 jar 包)
6.创建 export_common 子模块(打包方式是 jar 包)
在 export_parent 的 pom.xml 文件中引入坐标依赖
<2> 导入依赖
在export_web_manager 子模块的pom文件内导入依赖 代码如下:
<dependencies>
<dependency>
<groupId>cn.itcast</groupId>
<artifactId>export_service_system</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
在export_service_system 子模块的pom文件中导入依赖 代码如下:
<dependencies>
<dependency>
<groupId>cn.itcast</groupId>
<artifactId>export_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
在export_dao 子模块的pom文件中导入依赖 代码如下:
<dependencies>
<dependency>
<groupId>cn.itcast</groupId>
<artifactId>export_domain</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
export_parent 的 pom.xml 内的坐标依赖 代码如下:
<!-- 集中定义依赖版本号 -->
<properties>
<junit.version>4.12</junit.version>
<spring.version>5.0.2.RELEASE</spring.version>
<pagehelper.version>5.1.2</pagehelper.version>
<servlet-api.version>2.5</servlet-api.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mysql.version>5.1.32</mysql.version>
<druid.version>1.0.9</druid.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<activemq.version>5.11.2</activemq.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.11.0.GA</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!-- 缓存 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
<!--json-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<!--shiro-->
<!--shiro和spring整合-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!--shiro核心包-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.3.2</version>
</dependency>
<!--ehcache-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>3.2.3</version>
</dependency>
<!-- cxf 进行rs开发 必须导入 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.0.1</version>
</dependency>
<!-- 日志引入 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<!-- 客户端 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.0.1</version>
</dependency>
<!-- 扩展json提供者 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>3.0.1</version>
</dependency>
<!-- 转换json工具包,被extension providers 依赖 -->
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.7</version>
</dependency>
<!--activeMq-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Javamail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.4</version>
</dependency>
<!--文件上传-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!--七牛云-->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>[7.2.0, 7.2.99]</version>
</dependency>
<!--poi坐标-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.1</version>
</dependency>
<!--jasperreports 坐标-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.olap4j</groupId>
<artifactId>olap4j</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<!--定时任务-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
5.2 工程依赖结构
5.3 环境搭建
搭建 mybatis 环境
搭建 springioc 环境
整合 mybatis和spring
搭建 springioc 环境
整合
1.创建 export_parent 父工程(打包方式选择 pom)
删除src目录-在pom文件中带入依赖
2.创建 export_web_manager 子模块(打包方式是 war 包)
3.创建 export_service_system 子模块(打包方式是 jar 包)
4.创建 export_domain 子模块(打包方式是 jar 包)
5.创建 export_dao 子模块(打包方式是 jar 包)
6.创建 export_common 子模块(打包方式是 jar 包)
环境搭建步骤如下:
<1> 在 export_domain 子模块创建实体类Company(和数据库中的表对应)
<2> 在 export_dao 子模块创建CompanyDao接口
<3> 在 export_dao 子模块的Resources目录下创建CompanyDao.xml配置文件
<4> 在 export_service_system 子模块创建CompanyService接口
<5>在 export_service_system 子模块创建CompanyService接口的实现类CompanyServiceImpl
<6>在 export_service_system 子模块的Resources的目录下创建applicationContext-service.xml配置文件
<!--包扫描:开启注解支持-->
<context:component-scan base-package="cn.itcast.service"></context:component-scan>
<7>在 export_service_system 子模块的test的目录下创建CompanyServiceText测试类
package cn.itcast.test;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationContext-*.xml")
public class CompanyServiceTest {
@Autowired
private CompanyService companyService;
@Test
public void testFindAll() {
List<Company> list = companyService.findAll();
for (Company company : list) {
System.out.println(company);
}
}
}
<8>整合mybatis和springioc
在 export_service_system 子模块的Resources的目录下的applicationContext-service.xml中添加事务
<!--事务配置:xml配置-->
<!--1.创建事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--2.事务通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--service层方法对事务的支持配置-->
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="save*" read-only="false" propagation="REQUIRED"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--3.配置事务AOP-->
<aop:config>
<aop:pointcut id="pt" expression="execution(* cn.itcast.service.*.impl.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"></aop:advisor>
</aop:config>
<9>测试mybatis和springioc是否整合成功
<10> 在export_web_manager 子模块内创建CompanyController
<11> 在export_web_manager 子模块内创建springmvc.xml配置文件
<12> 在export_web_manager 子模块内修改web.xml配置文件
<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">
<!-- 监听器监听其他的spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*: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>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定加载的配置文件 ,通过参数contextConfigLocation加载-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<!--加载顺序-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- xxxx.abc-->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
<!--
<url-pattern>/</url-pattern>
-->
</servlet-mapping>
<!-- Shiro Security filter filter-name这个名字的值将来还会在spring中用到
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
</web-app>
<13>修改CompanyController
<14> 添加company-list.jsp页面
<15> 部署tomcat
并对tomcat起别名
<16> 日期转换器
修改export_web_manager 子模块内springmvc.xml配置文件
<17> 异常处理
制造异常
处理异常
异常跳转页面
6. 实现企业列表查询
6.1 表结构分析
CREATE TABLE `ss_company` (
`id` varchar(40) NOT NULL COMMENT 'ID',
`name` varchar(255) DEFAULT NULL COMMENT '公司名称',
`expiration_date` datetime DEFAULT NULL COMMENT '到期时间',
`address` varchar(255) DEFAULT NULL COMMENT '公司地址',
`license_id` varchar(255) DEFAULT NULL COMMENT '营业执照-图片',
`representative` varchar(255) DEFAULT NULL COMMENT '法人代表',
`phone` varchar(255) DEFAULT NULL COMMENT '公司电话',
`company_size` varchar(255) DEFAULT NULL COMMENT '公司规模',
`industry` varchar(255) DEFAULT NULL COMMENT '所属行业',
`remarks` varchar(255) DEFAULT NULL COMMENT '备注',
`state` int(2) DEFAULT '1' COMMENT '状态',
`balance` double DEFAULT NULL COMMENT '当前余额',
`city` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
6.2 需求分析
SSM整合:
实体类
Dao:
基于动态代理方式使用mybatis
Dao接口
Dao映射文件(namespace,id)
Service
Service接口和实现类
事务
测试:查询全部列表
Web:
Controller
基本页面
Mvc的配置
Web.xml的配置
6.3 代码实现
6.3.1 Dao层代码
6.3.1.1 接口
//企业持久层
public interface CompanyDao {
//查询所有企业
List<Company> findAll();
}
6.3.1.2 映射文件
<mapper namespace="cn.itcast.dao.company.CompanyDao" >
<!--配置映射关系-->
<resultMap id="BaseResultMap" type="cn.itcast.domain.company.Company">
<!--主键id-->
<!--其他属性-->
<id property="id" column="id"></id>
<result property="name" column="name"></result>
<result property="expirationDate" column="expiration_date"></result>
<result property="address" column="address"></result>
<result property="licenseId" column="license_id"></result>
<result property="representative" column="representative"></result>
<result property="phone" column="phone"></result>
<result property="companySize" column="company_size"></result>
<result property="industry" column="industry"></result>
<result property="remarks" column="remarks"></result>
<result property="state" column="state"></result>
<result property="balance" column="balance"></result>
<result property="city" column="city"></result>
</resultMap>
<!--查询所有企业-->
<select id="findAll" resultMap="BaseResultMap">
select * from ss_company
</select>
</mapper>
6.3.1.3 Spriing配置文件
<!--1.加载配置文件-->
<context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
<!--2.创建datasource-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
</bean>
<!--3.创建sqlSessionfactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--4.配置自动扫描映射文件,创建接口动态代理对象-->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.itcast.dao"></property>
</bean>
6.3.2 Service层代码
6.3.2.1 接口
//企业service接口
public interface CompanyService {
List<Company> findAll();
}
6.3.2.2 实现类
/**
* 企业service实现类
*/
@Service
public class CompanyServiceImpl implements CompanyService {
@Autowired
private CompanyDao companyDao;
@Override
public List<Company> findAll() {
return companyDao.findAll();
}
}
6.3.2.3 Spring配置文件
<!--包扫描:开启注解支持-->
<context:component-scan base-package="cn.itcast.service"></context:component-scan>
<!--事务配置:xml配置-->
<!--1.创建事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--2.事务通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--service层方法对事务的支持配置-->
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="save*" read-only="false" propagation="REQUIRED"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--3.配置事务AOP-->
<aop:config>
<aop:pointcut id="pt" expression="execution(* cn.itcast.service.*.impl.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"></aop:advisor>
</aop:config>
6.3.3 Controller代码
6.3.3.1 Controller代码
/**
* 企业控制器代码
*/
@Controller
@RequestMapping(value = "/company")
public class CompanyController {
@Autowired
private CompanyService companyService;
@RequestMapping(value="/list",name = "查询全部企业列表")
public String list(HttpServletRequest request) {
//1.查询全部
List<Company> list = companyService.findAll();
//2.将数据存入request域中
request.setAttribute("list",list);
//3.返回跳转的页面路径
return "company/company-list";
}
@RequestMapping(value="/edit",name = "编辑企业")
public String edit(Date date) {
System.out.println(date);
return "success";
}
}
6.3.3.2 spring文件
<!--包扫描-->
<context:component-scan base-package="cn.itcast.web"></context:component-scan>
<!--1.视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--2.注册异常处理器
<bean class="cn.itcast.web.exceptions.CustomExceptionResolver"></bean>
-->
<!--3.配置日期转化器-->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.itcast.web.converter.StringToDateConverter"></bean>
</set>
</property>
</bean>
<!--4.文件解析器
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
-->
<!--3.annotation driven-->
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
6.3.3.3 web.xml文件
<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">
<!-- 监听器监听其他的spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*: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>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定加载的配置文件 ,通过参数contextConfigLocation加载-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<!--加载顺序-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- xxxx.abc-->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
<!--
<url-pattern>/</url-pattern>
-->
</servlet-mapping>
<!-- Shiro Security filter filter-name这个名字的值将来还会在spring中用到
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
</web-app>
7. 日期与统一异常处理
7.1 日期处理
/**
* 自定义类型转化器
* 实现Converter接口
*/
public class StringToDateConverter implements Converter<String,Date> {
@Override
public Date convert(String source) {
Date date = null;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(source);
}catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
配置
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.itcast.web.converter.StringToDateConverter"></bean>
</set>
</property>
</bean>
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
7.2 异常处理
/**
* 统一异常处理
* 实现接口:HandlerExceptionResolver
*/
@Component
public class CustomExceptionResolver implements HandlerExceptionResolver {
/**
* 1.配置错误信息
* 2.跳转错误页面
*/
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
ex.printStackTrace();
ModelAndView mv = new ModelAndView();
mv.setViewName("error");
mv.addObject("errorMsg","对不起,我错了");
mv.addObject("ex",ex);
return mv;
}
}
面试总结:
1 . 云服务的三种模式
2. 原型分析 用例图
3. 日期处理,异常处理
4. 业务逻辑
作业:
1. 搭建环境 !!!!!!!
2. 预习
更多推荐
所有评论(0)