使用技術(shù)
在畢業(yè)設(shè)計(jì)程序中主要使用了SSM框架坯沪、Spring-Securtiy、Ajax扛芽、HTML骂蓖、CSS、JS川尖、JSP等技術(shù)
SSM整合
-
Spring整合Mybatis
在resources目錄下登下,創(chuàng)建applicationContext.xml進(jìn)行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連接池連接數(shù)據(jù)庫,即整合MyBatis
由于我使用的mysql版本8.0以上被芳,所以采用com.mysql.cj.jdbc.Driver包進(jìn)行連接银酬,并在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工廠,將數(shù)據(jù)庫信息傳入
<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框架聲明式事務(wù)管理及事務(wù)管理器
<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目錄下筐钟,創(chuàng)建springmvc.xml進(jìn)行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>
-
配置頁面靜態(tài)資源
<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"/>
項(xiàng)目思路
通過鏈接(href)或者表格的action來發(fā)送Ajax請求,將消息傳遞到controller中進(jìn)行處理
action = "${pageContext.request.contextPath}/user/register"
href = "${pageContext.request.contextPath}/route/route_all"
后臺處理完數(shù)據(jù)后通過ModelAndView進(jìn)行數(shù)據(jù)轉(zhuǎn)發(fā)和頁面跳轉(zhuǎn)
@RequestMapping("/route_all")
public ModelAndView route_all() throws Exception {
ModelAndView mv = new ModelAndView();
List<Route> routeList = routeService.find_All();
mv.addObject("routeList",routeList);//數(shù)據(jù)
mv.setViewName("route_list");//視圖
return mv;
}