SSM框架实现基本的登录注册功能
1.ssm框架需要的jar包
SSM
包括六层架构
1 controller层
2 dao层
3 model层
4 service层
5 service.impl层
6 mapper层
其中⽤到mvc注解的有controller层和serviceImpl层
⾸先controller层需要注解 @controller
然后表单对应的层 @RequestMapping("/user")
然后controller类对应的⽅法也要加对应的@RequestMapping("/⽅法名")
引⽤某层的,必须注解加@Resource
⽽ ServiceImpl层类前⾯先加上@Service("/⽗接⼝") ;引⼊哪层必须加@Resource
2 配置⽂件  四个配置⽂件
2.l
<!-- 配置mybatis的sqlSessionFactory -->
<bean id="sqlSessionFactory" class="batis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- ⾃动扫描l⽂件 -->
<property name="mapperLocations" value="classpath:com/java/mappers/*.xml"></property>        <!-- mybatis配置⽂件 -->
<property name="configLocation" value="l"></property>
</bean>
<!-- DAO接⼝所在包名,Spring会⾃动查其下的类 -->
<bean class="batis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.java.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>    </bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
ssm框架主要代码在哪里
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置事务通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务传播属性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事务切⾯ -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.java.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
</beans>
2.2 log4j.properties
log4j.appender.appender1=org.apache.log4j.ConsoleAppender
log4j.appender.appender2=org.apache.log4j.FileAppender
log4j.appender.appender2.File=C:/
log4j.appender.appender1.layout=org.apache.log4j.TTCCLayout
log4j.appender.appender2.layout=org.apache.log4j.TTCCLayout
2.l
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-////DTD Config 3.0//EN"
"/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 别名 -->
<typeAliases>
<package name="del"/>
</typeAliases>
</configuration>
2.l
<!-- 使⽤注解的包,包括⼦集 -->
<context:component-scan base-package="ller" />
<!-- 视图解析器  cotrlloer会返回相应的jsp -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/" />
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
运⾏结果图和后续代码⽂件下讲发(现在主要是配置⽂件)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。