美文网首页
SSM框架毕设项目回顾

SSM框架毕设项目回顾

作者: JayMeWangGL | 来源:发表于2020-06-12 16:37 被阅读0次

使用技术

在毕业设计程序中主要使用了SSM框架、Spring-Securtiy、Ajax、HTML、CSS、JS、JSP等技术


SSM整合

  • Spring整合Mybatis

在resources目录下,创建applicationContext.xml进行Spring和Mybatis的整合。其中包括:
  • 开启注解扫描(dao和service)
<context:component-scan base-package="com.wgl.dao"></context:component-scan>
<context:component-scan base-package="com.wgl.service"></context:component-scan>
  • 使用c3p0连接池连接数据库,即整合MyBatis

由于我使用的mysql版本8.0以上,所以采用com.mysql.cj.jdbc.Driver包进行连接,并在Url路径中添加serverTimezone

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql:///XXXXXX?serverTimezone=Asia/Shanghai"></property>
        <property name="user" value="root"></property>
        <property name="password" value="XXXX"></property>
    </bean>
  • 配置sqlSessionFactory工厂,将数据库信息传入
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
  • 配置dao接口路径
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.wgl.dao"></property>
    </bean>
  • 配置Spring框架声明式事务管理及事务管理器
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
  • SpringMVC整合Spring

在resources目录下,创建springmvc.xml进行Spring和SpringMVC的整合。其中包括:
  • 配置只扫描controller
<context:component-scan base-package="com.wgl.controller"></context:component-scan>
  • 配置视图解析器
    <bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
  • 配置页面静态资源
    <mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
    <mvc:resources mapping="/img/**" location="/img/"></mvc:resources>
    <mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
    <mvc:resources mapping="/plugins/**" location="/plugins/"></mvc:resources>
  • 开启注解以及AOP
    <mvc:annotation-driven></mvc:annotation-driven>
    <aop:aspectj-autoproxy proxy-target-class="true"/>

项目思路

通过链接(href)或者表格的action来发送Ajax请求,将消息传递到controller中进行处理

action = "${pageContext.request.contextPath}/user/register"

href = "${pageContext.request.contextPath}/route/route_all"

后台处理完数据后通过ModelAndView进行数据转发和页面跳转

@RequestMapping("/route_all")
    public ModelAndView route_all() throws Exception {
        ModelAndView mv =  new ModelAndView();
        List<Route> routeList = routeService.find_All();
        mv.addObject("routeList",routeList);//数据
        mv.setViewName("route_list");//视图
        return mv;
    }

相关文章

网友评论

      本文标题:SSM框架毕设项目回顾

      本文链接:https://www.haomeiwen.com/subject/juqntktx.html