码迷,mamicode.com
首页 > 其他好文 > 详细

基于SSM的租赁管理系统1.0_20161225_框架搭建

时间:2016-12-26 00:18:07      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:efi   数据库表   date   ebe   javaee   name   port   work   dex   

搭建SSM底层框架

技术分享

 

1. 利用mybatis反向工程generatorSqlmapCustom完成对数据库十表的映射

generatorConfig.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 
 6 <generatorConfiguration>
 7     <context id="testTables" targetRuntime="MyBatis3">
 8         <commentGenerator>
 9             <!-- 是否去除自动生成的注释 true:是 : false:否 -->
10             <property name="suppressAllComments" value="true" />
11         </commentGenerator>
12         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
13         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
14             connectionURL="jdbc:mysql://localhost:3306/test" userId="root"
15             password="root">
16         </jdbcConnection>
17         <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 
18             NUMERIC 类型解析为java.math.BigDecimal -->
19         <javaTypeResolver>
20             <property name="forceBigDecimals" value="false" />
21         </javaTypeResolver>
22 
23         <!-- targetProject:生成PO类的位置 -->
24         <javaModelGenerator targetPackage="org.guangsoft.po"
25             targetProject=".\src">
26             <!-- enableSubPackages:是否让schema作为包的后缀 -->
27             <property name="enableSubPackages" value="false" />
28             <!-- 从数据库返回的值被清理前后的空格 -->
29             <property name="trimStrings" value="true" />
30         </javaModelGenerator>
31         <!-- targetProject:mapper映射文件生成的位置 -->
32         <sqlMapGenerator targetPackage="mybatis" 
33             targetProject=".\src">
34             <!-- enableSubPackages:是否让schema作为包的后缀 -->
35             <property name="enableSubPackages" value="false" />
36         </sqlMapGenerator>
37         <!-- targetPackage:mapper接口生成的位置 -->
38         <javaClientGenerator type="XMLMAPPER"
39             targetPackage="org.guangsoft.mapper" 
40             targetProject=".\src">
41             <!-- enableSubPackages:是否让schema作为包的后缀 -->
42             <property name="enableSubPackages" value="false" />
43         </javaClientGenerator>
44         <!-- 指定数据库表 -->
45         <table schema="" tableName="users"></table>
46         <table schema="" tableName="roles"></table>
47         <table schema="" tableName="privileges"></table>
48         <table schema="" tableName="items"></table>
49         <table schema="" tableName="cars"></table>
50         <table schema="" tableName="clients"></table>
51         <table schema="" tableName="loginlog"></table>
52         <table schema="" tableName="systemlog"></table>
53         <table schema="" tableName="rents"></table>
54         <table schema="" tableName="checks"></table>
55     </context>
56 </generatorConfiguration>

2. 配置mybatis

SqlMapperConfig.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE configuration
 3         PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 4         "http://mybatis.org/dtd/mybatis-3-config.dtd">
 5 <configuration>
 6 <!-- 配置分页插件 -->
 7     <plugins>
 8         <plugin interceptor="com.github.pagehelper.PageHelper">
 9             <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->        
10             <property name="dialect" value="mysql"/>
11         </plugin>
12     </plugins>
13 </configuration>

3. 配置spring-dao

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

applicationContext-dao.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 7     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
 8     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 9     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
10     <!-- 解析properties文件的工具类 -->
11     <context:property-placeholder location="classpath:resource/*.properties"/>
12     
13     <!-- 配置数据源 -->
14     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 
15         <!-- 数据库驱动 -->
16         <property name="driverClassName" value="${jdbc.driver}" />
17         <!-- 基本属性 url、user、password -->
18         <property name="url" value="${jdbc.url}" />
19         <property name="username" value="${jdbc.username}" />
20         <property name="password" value="${jdbc.password}" />
21         <!-- 配置初始化大小、最小、最大 -->
22         <property name="initialSize" value="1" />
23         <property name="minIdle" value="1" /> 
24         <property name="maxActive" value="20" />
25         <!-- 配置获取连接等待超时的时间 -->
26         <property name="maxWait" value="60000" />
27         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
28         <property name="timeBetweenEvictionRunsMillis" value="60000" />
29         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
30         <property name="minEvictableIdleTimeMillis" value="300000" />
31         <property name="validationQuery" value="SELECT ‘x‘" />
32         <property name="testWhileIdle" value="true" />
33         <property name="testOnBorrow" value="false" />
34         <property name="testOnReturn" value="false" />
35         <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
36         <property name="poolPreparedStatements" value="false" />
37         <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
38         <!-- 配置监控统计拦截的filters -->
39         <property name="filters" value="stat" /> 
40     </bean>
41     
42     <!-- sqlSessionfactory -->
43     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
44         <property name="configLocation" value="classpath:mybatis/SqlMapperConfig.xml"/>
45         <property name="dataSource" ref="dataSource"/>
46     </bean>
47     
48     <!-- 扫描代理类 -->
49     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
50         <property name="basePackage" value="mybatis"/>
51     </bean>
52 </beans>

applicationContext-service.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 7     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
 8     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 9     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
10         <context:component-scan base-package="org.guangsoft.service"/>
11 </beans>

applicationContext-tarns.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 7     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
 8     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 9     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
10     <!-- 配置事物管理器的切面 -->
11     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
12         <property name="dataSource" ref="dataSource"/>
13     </bean>
14     
15     <!-- 通知 -->
16     <tx:advice id="Advice" transaction-manager="transactionManager">
17         <!-- 事物传播行为 -->
18         <tx:attributes>
19             <!-- 传播行为 -->
20             <tx:method name="save*" propagation="REQUIRED" />
21             <tx:method name="insert*" propagation="REQUIRED" />
22             <tx:method name="add*" propagation="REQUIRED" />
23             <tx:method name="create*" propagation="REQUIRED" />
24             <tx:method name="delete*" propagation="REQUIRED" />
25             <tx:method name="update*" propagation="REQUIRED" />
26             <tx:method name="drop*" propagation="REQUIRED" />
27             <tx:method name="modify*" propagation="REQUIRED" />
28             <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
29             <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
30             <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
31         </tx:attributes>
32     </tx:advice>
33     <aop:config>
34         <aop:advisor advice-ref="Advice" pointcut="execution(* org.guangsoft.service.*.*(..))" />
35     </aop:config>
36 </beans>

springmvc.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
 8         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 9         <!-- 扫描controller组件 -->
10         <context:component-scan base-package="org.guangsoft.controller"/>
11 
12         <!-- 注册注解驱动 -->
13         <mvc:annotation-driven></mvc:annotation-driven>
14         
15         <!-- 配置视图解析 -->
16         <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17             <property name="prefix" value="/" />
18             <property name="suffix" value=".jsp" />
19         </bean>
20         </beans>

 4. 配置web.xml

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 6     <!-- 启动spring -->
 7     <context-param>
 8         <param-name>contextConfigLocation</param-name>
 9         <param-value>classpath:spring/applicationContext-*.xml</param-value>
10     </context-param>
11     <listener>
12         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
13     </listener>
14 
15     <!-- 解决post乱码 -->
16     <filter>
17         <filter-name>CharacterEncodingFilter</filter-name>
18         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
19         <init-param>
20             <param-name>encoding</param-name>
21             <param-value>utf-8</param-value>
22         </init-param>
23     </filter>
24     <filter-mapping>
25         <filter-name>CharacterEncodingFilter</filter-name>
26         <url-pattern>/*</url-pattern>
27     </filter-mapping>
28 
29     <!-- 启动springmvc -->
30     <servlet>
31         <servlet-name>guangsoft</servlet-name>
32         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
33         <!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
34         <init-param>
35             <param-name>contextConfigLocation</param-name>
36             <param-value>classpath:spring/springmvc.xml</param-value>
37         </init-param>
38         <load-on-startup>1</load-on-startup>
39     </servlet>
40 
41     <servlet-mapping>
42         <servlet-name>guangsoft</servlet-name>
43         <url-pattern>*.do</url-pattern>
44     </servlet-mapping>
45 
46     <welcome-file-list>
47         <welcome-file>index.jsp</welcome-file>
48     </welcome-file-list>
49 </web-app>

 

基于SSM的租赁管理系统1.0_20161225_框架搭建

标签:efi   数据库表   date   ebe   javaee   name   port   work   dex   

原文地址:http://www.cnblogs.com/guanghe/p/6220525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!