报销流程
图片.png数据库设计
图片.png项目创建
图片.png包及全局配置
图片.pngdao配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--开启自动扫描-->
<context:component-scan base-package="com.alan.oa.dao"></context:component-scan>
<!--配置数据源-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/oa?characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!--配置session工厂-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--关联声明的数据源-->
<property name="dataSource" ref="dataSource"></property>
<!--配置别名,entity下的类不需要配置包的全路径-->
<property name="typeAliasesPackage" value="com.alan.oa.entity"></property>
</bean>
<!--配置映射器接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sessionFactory"></property>
<!--配置接口与映射文件对应,需要放置在dao包里面-->
<property name="basePackage" value="com.alan.oa.dao"></property>
</bean>
</beans>
biz配置
- 声明式事务需要配置在业务层 dao层封装为事务太细了,web层一次次请求封装为事务太粗了,放在业务层声明事务相对合理。 一个业务功能,要么都成功,要么都失败。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--将dao层的spring配置文件引入进来-->
<import resource="spring-dao.xml"></import>
<!--开启自动扫描-->
<context:component-scan base-package="com.alan.oa.biz"></context:component-scan>
<!--开启aspectj自动代理-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!--配置声明式事务-->
<bean id="transationManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--声明通知-->
<tx:advice id="txAdvice" transaction-manager="transationManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="search*" read-only="true"/>
<!--其他方法,强制开启事务-->
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--将通知与切入点进行关联-->
<aop:config>
<aop:pointcut id="txpc" expression="execution(* com.alan.oa.biz.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txpc"/>
</aop:config>
</beans>
WEB配置
- dto 是页面数据与controller数据之间交互,类似dao层里面的entity包
- 在web.xml中配置springMVC加载
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="spring-biz.xml"/>
<!--开启自动扫描-->
<context:component-scan base-package="com.alan.oa.controller"/>
<mvc:annotation-driven/>
<!--静态资源交给servlet处理-->
<mvc:default-servlet-handler/>
<!--视图转换器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!--配置前缀和后缀-->
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
部门管理
1、实体类
2、dao接口与sql映射文件
3、biz接口与其实现类
4、控制器
5、页面
通过Spring注解进行格式转换
@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm")
private Date dealTime;
- 声明式事务封装在业务层。 每一个业务层的具体方法中的所有sql都是一个统一的事物,具有原子性、一致性、隔离性、持久性。
网友评论