基于Spring+SpringMVC+Mybatis的Web系统搭建


 

系统搭建的配置大同小异,本文在前人的基础上做了些许的改动,重写数据库,增加依据权限的动态菜单的实现,也增加了后台返回json格式数据的配置,详细参见完整源码

 

主要的后端架构:Spring+SpringMVC+Mybatis+Shiro+Maven 

IDE:IntelliJ IDEA 15.0.2

jdk:1.8.0_66

 

系统完整源码

https://github.com/Wellat/Factor

 

系统目录结构

 

跑起来效果

 

 

搭建步骤

1、用Idea创建maven项目

2、配置pom.xml文件,添加依赖

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0"
  3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5     <modelVersion>4.0.0</modelVersion>
  6 
  7     <groupId>com.hemi</groupId>
  8     <artifactId>factor</artifactId>
  9     <version>1.0.0</version>
 10     <packaging>war</packaging>
 11 
 12     <build>
 13         <finalName>factor</finalName>
 14         <plugins>
 15             <!-- Mybatis generator代码生成插件 配置 -->
 16             <plugin>
 17                 <groupId>org.mybatis.generator</groupId>
 18                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 19                 <version>${plugin.mybatis.generator}</version>
 20                 <configuration>
 21                     <configurationFile>${mybatis.generator.generatorConfig.xml}</configurationFile>
 22                     <overwrite>true</overwrite>
 23                     <verbose>true</verbose>
 24                 </configuration>
 25             </plugin>
 26 
 27             <!--Maven编译插件 配置-->
 28             <plugin>
 29                 <groupId>org.apache.maven.plugins</groupId>
 30                 <artifactId>maven-compiler-plugin</artifactId>
 31                 <version>${plugin.maven-compiler}</version>
 32                 <configuration>
 33                     <source>${project.build.jdk}</source>
 34                     <target>${project.build.jdk}</target>
 35                     <encoding>${project.build.sourceEncoding}</encoding>
 36                 </configuration>
 37             </plugin>
 38         </plugins>
 39 
 40         <!--配置Maven 对resource文件 过滤 -->
 41         <resources>
 42             <resource>
 43                 <directory>src/main/resources</directory>
 44                 <includes>
 45                     <include>**/*.properties</include>
 46                     <include>**/*.xml</include>
 47                 </includes>
 48                 <filtering>true</filtering>
 49             </resource>
 50             <resource>
 51                 <directory>src/main/java</directory>
 52                 <includes>
 53                     <include>**/*.properties</include>
 54                     <include>**/*.xml</include>
 55                 </includes>
 56                 <filtering>true</filtering>
 57             </resource>
 58         </resources>
 59     </build>
 60 
 61     <properties>
 62         <!-- base setting -->
 63         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 64         <project.build.locales>zh_CN</project.build.locales>
 65         <project.build.jdk>1.8</project.build.jdk>
 66 
 67         <!-- plugin setting -->
 68         <mybatis.generator.generatorConfig.xml>${basedir}/src/test/resources/generatorConfig.xml</mybatis.generator.generatorConfig.xml>
 69         <mybatis.generator.generatorConfig.properties>file:///${basedir}/src/test/resources/generatorConfig.properties</mybatis.generator.generatorConfig.properties>
 70 
 71         <!-- plugin versions -->
 72         <plugin.mybatis.generator>1.3.1</plugin.mybatis.generator>
 73         <plugin.maven-compiler>3.1</plugin.maven-compiler>
 74 
 75         <!-- lib versions -->
 76         <junit.version>4.11</junit.version>
 77         <spring.version>4.1.6.RELEASE</spring.version>
 78         <mybatis.version>3.2.2</mybatis.version>
 79         <mybatis.spring.version>1.2.2</mybatis.spring.version>
 80         <mysql.connector.version>5.1.30</mysql.connector.version>
 81         <postgresql.version>9.1-901.jdbc4</postgresql.version>
 82         <slf4j.version>1.6.6</slf4j.version>
 83         <log4j.version>1.2.12</log4j.version>
 84         <httpclient.version>4.1.2</httpclient.version>
 85         <jackson.version>1.9.13</jackson.version>
 86         <c3p0.version>0.9.1.2</c3p0.version>
 87         <druid.version>1.0.5</druid.version>
 88         <tomcat.jdbc.version>7.0.53</tomcat.jdbc.version>
 89         <jstl.version>1.2</jstl.version>
 90         <google.collections.version>1.0</google.collections.version>
 91         <cglib.version>3.1</cglib.version>
 92         <shiro.version>1.2.3</shiro.version>
 93         <commons.fileupload.version>1.3.1</commons.fileupload.version>
 94         <commons.codec.version>1.9</commons.codec.version>
 95         <commons.net.version>3.3</commons.net.version>
 96         <aspectj.version>1.6.12</aspectj.version>
 97         <netty.version>4.0.18.Final</netty.version>
 98         <hibernate.validator.version>5.1.1.Final</hibernate.validator.version>
 99         <redis.version>2.8.1</redis.version>
100         <fastjson.version>1.2.17</fastjson.version>
101     </properties>
102 
103     <dependencies>
104 
105         <!-- fastjson -->
106         <dependency>
107             <groupId>com.alibaba</groupId>
108             <artifactId>fastjson</artifactId>
109             <version>${fastjson.version}</version>
110         </dependency>
111 
112         <dependency>
113             <groupId>redis.clients</groupId>
114             <artifactId>jedis</artifactId>
115             <version>${redis.version}</version>
116         </dependency>
117 
118         <!-- junit -->
119         <dependency>
120             <groupId>junit</groupId>
121             <artifactId>junit</artifactId>
122             <version>${junit.version}</version>
123         </dependency>
124 
125         <!-- springframe start -->
126         <dependency>
127             <groupId>org.springframework</groupId>
128             <artifactId>spring-core</artifactId>
129             <version>${spring.version}</version>
130         </dependency>
131 
132         <dependency>
133             <groupId>org.springframework</groupId>
134             <artifactId>spring-web</artifactId>
135             <version>${spring.version}</version>
136         </dependency>
137 
138         <dependency>
139             <groupId>org.springframework</groupId>
140             <artifactId>spring-oxm</artifactId>
141             <version>${spring.version}</version>
142         </dependency>
143 
144         <dependency>
145             <groupId>org.springframework</groupId>
146             <artifactId>spring-tx</artifactId>
147             <version>${spring.version}</version>
148         </dependency>
149 
150         <dependency>
151             <groupId>org.springframework</groupId>
152             <artifactId>spring-jdbc</artifactId>
153             <version>${spring.version}</version>
154         </dependency>
155 
156         <dependency>
157             <groupId>org.springframework</groupId>
158             <artifactId>spring-webmvc</artifactId>
159             <version>${spring.version}</version>
160         </dependency>
161 
162         <dependency>
163             <groupId>org.springframework</groupId>
164             <artifactId>spring-aop</artifactId>
165             <version>${spring.version}</version>
166         </dependency>
167 
168         <dependency>
169             <groupId>org.springframework</groupId>
170             <artifactId>spring-context-support</artifactId>
171             <version>${spring.version}</version>
172         </dependency>
173 
174         <dependency>
175             <groupId>org.springframework</groupId>
176             <artifactId>spring-test</artifactId>
177             <version>${spring.version}</version>
178         </dependency>
179         <!-- springframe end -->
180 
181         <!-- mybatis start-->
182         <dependency>
183             <groupId>org.mybatis</groupId>
184             <artifactId>mybatis</artifactId>
185             <version>${mybatis.version}</version>
186         </dependency>
187 
188         <dependency>
189             <groupId>org.mybatis</groupId>
190             <artifactId>mybatis-spring</artifactId>
191             <version>${mybatis.spring.version}</version>
192         </dependency>
193         <!--mybatis end-->
194 
195         <!-- mysql-connector -->
196         <dependency>
197             <groupId>mysql</groupId>
198             <artifactId>mysql-connector-java</artifactId>
199             <version>${mysql.connector.version}</version>
200         </dependency>
201 
202         <!-- DruidDataSource -->
203         <dependency>
204             <groupId>com.alibaba</groupId>
205             <artifactId>druid</artifactId>
206             <version>${druid.version}</version>
207         </dependency>
208 
209 
210         <!-- log start -->
211         <dependency>
212             <groupId>log4j</groupId>
213             <artifactId>log4j</artifactId>
214             <version>${log4j.version}</version>
215         </dependency>
216         <dependency>
217             <groupId>org.slf4j</groupId>
218             <artifactId>slf4j-api</artifactId>
219             <version>${slf4j.version}</version>
220         </dependency>
221         <dependency>
222             <groupId>org.slf4j</groupId>
223             <artifactId>slf4j-log4j12</artifactId>
224             <version>${slf4j.version}</version>
225         </dependency>
226         <!-- log end -->
227 
228         <!-- servlet api -->
229         <dependency>
230             <groupId>javax.servlet</groupId>
231             <artifactId>javax.servlet-api</artifactId>
232             <version>3.0.1</version>
233             <scope>provided</scope>
234         </dependency>
235 
236         <!-- jstl -->
237         <dependency>
238             <groupId>javax.servlet</groupId>
239             <artifactId>jstl</artifactId>
240             <version>${jstl.version}</version>
241         </dependency>
242 
243         <!-- start apache -->
244         <dependency>
245             <groupId>commons-fileupload</groupId>
246             <artifactId>commons-fileupload</artifactId>
247             <version>${commons.fileupload.version}</version>
248         </dependency>
249 
250         <dependency>
251             <groupId>org.apache.httpcomponents</groupId>
252             <artifactId>httpclient</artifactId>
253             <version>${httpclient.version}</version>
254         </dependency>
255 
256         <dependency>
257             <groupId>commons-codec</groupId>
258             <artifactId>commons-codec</artifactId>
259             <version>${commons.codec.version}</version>
260         </dependency>
261 
262         <dependency>
263             <groupId>commons-net</groupId>
264             <artifactId>commons-net</artifactId>
265             <version>${commons.net.version}</version>
266         </dependency>
267 
268         <dependency>
269             <groupId>commons-logging</groupId>
270             <artifactId>commons-logging</artifactId>
271             <version>1.1.3</version>
272         </dependency>
273         <dependency>
274             <groupId>commons-collections</groupId>
275             <artifactId>commons-collections</artifactId>
276             <version>3.2.1</version>
277         </dependency>
278 
279         <!-- end apache -->
280 
281         <!-- google -->
282         <dependency>
283             <groupId>com.google.collections</groupId>
284             <artifactId>google-collections</artifactId>
285             <version>${google.collections.version}</version>
286         </dependency>
287 
288         <!-- cglib -->
289         <dependency>
290             <groupId>cglib</groupId>
291             <artifactId>cglib-nodep</artifactId>
292             <version>${cglib.version}</version>
293         </dependency>
294 
295 
296         <!-- shiro -->
297         <dependency>
298             <groupId>org.apache.shiro</groupId>
299             <artifactId>shiro-spring</artifactId>
300             <version>${shiro.version}</version>
301         </dependency>
302         <dependency>
303             <groupId>org.apache.shiro</groupId>
304             <artifactId>shiro-ehcache</artifactId>
305             <version>${shiro.version}</version>
306         </dependency>
307         <dependency>
308             <groupId>org.apache.shiro</groupId>
309             <artifactId>shiro-core</artifactId>
310             <version>${shiro.version}</version>
311         </dependency>
312         <dependency>
313             <groupId>org.apache.shiro</groupId>
314             <artifactId>shiro-web</artifactId>
315             <version>${shiro.version}</version>
316         </dependency>
317         <dependency>
318             <groupId>org.apache.shiro</groupId>
319             <artifactId>shiro-quartz</artifactId>
320             <version>${shiro.version}</version>
321         </dependency>
322 
323         <!-- aspectjweaver -->
324         <dependency>
325             <groupId>org.aspectj</groupId>
326             <artifactId>aspectjweaver</artifactId>
327             <version>${aspectj.version}</version>
328         </dependency>
329         <dependency>
330             <groupId>org.aspectj</groupId>
331             <artifactId>aspectjrt</artifactId>
332             <version>${aspectj.version}</version>
333         </dependency>
334 
335         <!-- hibernate-validator -->
336         <dependency>
337             <groupId>org.hibernate</groupId>
338             <artifactId>hibernate-validator</artifactId>
339             <version>${hibernate.validator.version}</version>
340         </dependency>
341 
342         <!-- netty -->
343         <dependency>
344             <groupId>io.netty</groupId>
345             <artifactId>netty-all</artifactId>
346             <version>${netty.version}</version>
347         </dependency>
348 
349         <dependency>
350             <groupId>org.mybatis.generator</groupId>
351             <artifactId>mybatis-generator-core</artifactId>
352             <version>1.3.2</version>
353             <type>jar</type>
354             <scope>test</scope>
355         </dependency>
356 
357     </dependencies>
358 
359 </project>
pom.xml

3、配置web.xml

在系统 src/main 下创建 webapp/WEB-INF 二级目录,在WEB-INF下创建web.xml文件

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  4     <!-- Spring -->
  5     <!-- 配置Spring配置文件路径 -->
  6     <context-param>
  7         <param-name>contextConfigLocation</param-name>
  8         <param-value>
  9             classpath*:applicationContext.xml
 10             classpath*:applicationContext-shiro.xml
 11         </param-value>
 12     </context-param>
 13     <!-- 配置Spring上下文监听器 -->
 14     <listener>
 15         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 16     </listener>
 17     <!-- Spring -->
 18 
 19     <!-- 配置Spring字符编码过滤器 -->
 20     <filter>
 21         <filter-name>encodingFilter</filter-name>
 22         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
 23         <init-param>
 24             <param-name>encoding</param-name>
 25             <param-value>UTF-8</param-value>
 26         </init-param>
 27         <init-param>
 28             <param-name>forceEncoding</param-name>
 29             <param-value>true</param-value>
 30         </init-param>
 31     </filter>
 32     <filter-mapping>
 33         <filter-name>encodingFilter</filter-name>
 34         <url-pattern>/*</url-pattern>
 35     </filter-mapping>
 36 
 37     <!-- shiro 安全过滤器 -->
 38     <!-- 配置Shiro过滤器,先让Shiro过滤系统接收到的请求 -->
 39     <!-- 这里filter-name必须对应applicationContext.xml中定义的<bean id="shiroFilter"/> -->
 40     <!-- 使用[/*]匹配所有请求,保证所有的可控请求都经过Shiro的过滤 -->
 41     <!-- 通常会将此filter-mapping放置到最前面(即其他filter-mapping前面),以保证它是过滤器链中第一个起作用的 -->
 42     <filter>
 43         <filter-name>shiroFilter</filter-name>
 44         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 45         <!--<async-supported>true</async-supported>-->
 46         <init-param>
 47             <!-- 该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理 -->
 48             <param-name>targetFilterLifecycle</param-name>
 49             <param-value>true</param-value>
 50         </init-param>
 51     </filter>
 52     <filter-mapping>
 53         <filter-name>shiroFilter</filter-name>
 54         <url-pattern>/*</url-pattern>
 55     </filter-mapping>
 56 
 57     <!-- 配置log4j配置文件路径 -->
 58     <context-param>
 59         <param-name>log4jConfigLocation</param-name>
 60         <param-value>classpath:log4j.properties</param-value>
 61     </context-param>
 62     <!-- 60s 检测日志配置 文件变化 -->
 63     <context-param>
 64         <param-name>log4jRefreshInterval</param-name>
 65         <param-value>60000</param-value>
 66     </context-param>
 67 
 68     <!-- 配置Log4j监听器 -->
 69     <listener>
 70         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 71     </listener>
 72 
 73     <!-- Spring MVC 核心控制器 DispatcherServlet 配置 -->
 74     <servlet>
 75         <servlet-name>dispatcher</servlet-name>
 76         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 77         <init-param>
 78             <param-name>contextConfigLocation</param-name>
 79             <param-value>classpath*:spring-mvc.xml</param-value>
 80         </init-param>
 81         <load-on-startup>1</load-on-startup>
 82     </servlet>
 83     <servlet-mapping>
 84         <servlet-name>dispatcher</servlet-name>
 85         <!-- 拦截所有/rest/* 的请求,交给DispatcherServlet处理,性能最好 -->
 86         <url-pattern>/rest/*</url-pattern>
 87     </servlet-mapping>
 88 
 89     <!-- 首页 -->
 90     <welcome-file-list>
 91         <welcome-file>rest/index</welcome-file>
 92     </welcome-file-list>
 93 
 94     <!-- 错误页 -->
 95     <error-page>
 96         <error-code>404</error-code>
 97         <location>/rest/page/401</location>
 98     </error-page>
 99     <error-page>
100         <error-code>500</error-code>
101         <location>/rest/page/500</location>
102     </error-page>
103     <error-page>
104         <exception-type>org.apache.shiro.authz.AuthorizationException</exception-type>
105         <location>/rest/page/401</location>
106     </error-page>
107 
108 </web-app>
web.xml

4、配置Spring

①applicationContext.xml

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
  3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  4        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
  5        xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  6        xmlns:cache="http://www.springframework.org/schema/cache"
  7        xsi:schemaLocation="
  8     http://www.springframework.org/schema/context
  9     http://www.springframework.org/schema/context/spring-context.xsd
 10     http://www.springframework.org/schema/beans
 11     http://www.springframework.org/schema/beans/spring-beans.xsd
 12     http://www.springframework.org/schema/tx
 13     http://www.springframework.org/schema/tx/spring-tx.xsd
 14     http://www.springframework.org/schema/jdbc
 15     http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
 16     http://www.springframework.org/schema/cache
 17     http://www.springframework.org/schema/cache/spring-cache.xsd
 18     http://www.springframework.org/schema/aop
 19     http://www.springframework.org/schema/aop/spring-aop.xsd
 20     http://www.springframework.org/schema/util
 21     http://www.springframework.org/schema/util/spring-util.xsd">
 22 
 23     <!-- 自动扫描quick4j包 ,将带有注解的类 纳入spring容器管理 -->
 24     <context:component-scan base-package="com.hemi.factor"></context:component-scan>
 25 
 26     <!-- 引入配置文件 -->
 27     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 28         <property name="locations">
 29             <list>
 30                 <value>classpath*:application.properties</value>
 31             </list>
 32         </property>
 33     </bean>
 34 
 35     <!-- dataSource 配置 -->
 36     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
 37         <!-- 基本属性 url、user、password -->
 38         <property name="url" value="${jdbc.url}"/>
 39         <property name="username" value="${jdbc.username}"/>
 40         <property name="password" value="${jdbc.password}"/>
 41 
 42         <!-- 配置初始化大小、最小、最大 -->
 43         <property name="initialSize" value="${ds.initialSize}"/>
 44         <property name="minIdle" value="${ds.minIdle}"/>
 45         <property name="maxActive" value="${ds.maxActive}"/>
 46 
 47         <!-- 配置获取连接等待超时的时间 -->
 48         <property name="maxWait" value="${ds.maxWait}"/>
 49 
 50         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
 51         <property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}"/>
 52 
 53         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
 54         <property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}"/>
 55 
 56         <property name="validationQuery" value="SELECT 'x'"/>
 57         <property name="testWhileIdle" value="true"/>
 58         <property name="testOnBorrow" value="false"/>
 59         <property name="testOnReturn" value="false"/>
 60 
 61         <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
 62         <property name="poolPreparedStatements" value="false"/>
 63         <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
 64 
 65         <!-- 配置监控统计拦截的filters -->
 66         <property name="filters" value="stat"/>
 67     </bean>
 68 
 69     <!-- mybatis文件配置,扫描所有mapper文件 -->
 70     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource"
 71           p:configLocation="classpath:mybatis-config.xml"
 72           p:mapperLocations="classpath:com/hemi/factor/web/dao/*.xml"/>
 73 
 74     <!-- spring与mybatis整合配置,扫描所有dao -->
 75     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.hemi.factor.web.dao"
 76           p:sqlSessionFactoryBeanName="sqlSessionFactory"/>
 77 
 78     <!-- 对dataSource 数据源进行事务管理 -->
 79     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
 80           p:dataSource-ref="dataSource"/>
 81 
 82     <!-- 事务管理 通知 -->
 83     <tx:advice id="txAdvice" transaction-manager="transactionManager">
 84         <tx:attributes>
 85             <!-- 对insert,update,delete 开头的方法进行事务管理,只要有异常就回滚 -->
 86             <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
 87             <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
 88             <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
 89             <!-- select,count开头的方法,开启只读,提高数据库访问性能 -->
 90             <tx:method name="select*" read-only="true"/>
 91             <tx:method name="count*" read-only="true"/>
 92             <!-- 对其他方法 使用默认的事务管理 -->
 93             <tx:method name="*"/>
 94         </tx:attributes>
 95     </tx:advice>
 96 
 97     <!-- 事务 aop 配置 -->
 98     <aop:config>
 99         <aop:pointcut id="serviceMethods" expression="execution(* com.hemi.factor.web.service..*(..))"/>
100         <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
101     </aop:config>
102 
103     <!-- 配置使Spring采用CGLIB代理 -->
104     <aop:aspectj-autoproxy proxy-target-class="true"/>
105 
106     <!-- 启用对事务注解的支持 -->
107     <tx:annotation-driven transaction-manager="transactionManager"/>
108 
109     <!-- Cache配置 -->
110     <cache:annotation-driven cache-manager="cacheManager"/>
111     <bean id="ehCacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
112           p:configLocation="classpath:ehcache.xml"/>
113     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
114           p:cacheManager-ref="ehCacheManagerFactory"/>
115 </beans>
applicationContext.xml

②application.properties

含数据库连接设置

 1 ##JDBC Global Setting
 2 jdbc.driver=com.mysql.jdbc.Driver
 3 jdbc.url=jdbc:mysql://localhost:3306/factor?useUnicode=true&characterEncoding=utf-8
 4 jdbc.username=root
 5 jdbc.password=hemi
 6 
 7 ##DataSource Global Setting
 8 
 9 #配置初始化大小、最小、最大
10 ds.initialSize=1
11 ds.minIdle=1
12 ds.maxActive=20
13 
14 #配置获取连接等待超时的时间
15 ds.maxWait=60000
16 
17 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
18 ds.timeBetweenEvictionRunsMillis=60000
19 
20 #配置一个连接在池中最小生存的时间,单位是毫秒
21 ds.minEvictableIdleTimeMillis=300000
application.properties

③ehcache.xml

1 <?xml version="1.0" encoding="UTF-8"?>
2 <ehcache updateCheck="false" name="txswx-ehcache">
3     <diskStore path="java.io.tmpdir"/>
4     <!-- DefaultCache setting. -->
5     <defaultCache maxEntriesLocalHeap="10000" eternal="true" timeToIdleSeconds="300" timeToLiveSeconds="600"
6                   overflowToDisk="true" maxEntriesLocalDisk="100000"/>
7 </ehcache>
ehcache.xml

5、配置 Apache Shiro

①applicationContext-shiro.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xsi:schemaLocation="
 5        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 6        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
 7 
 8     <description>apache shiro配置</description>
 9 
10     <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
11         <!-- Shiro的核心安全接口,这个属性是必须的 -->
12         <property name="securityManager" ref="securityManager"/>
13         <!-- 要求登录时的链接(可根据项目的URL进行替换),非必须的属性,默认会自动寻找Web工程根目录下的"/login.jsp"页面 -->
14         <property name="loginUrl" value="/rest/page/login"/>
15         <property name="successUrl" value="/rest/index"/>
16         <property name="unauthorizedUrl" value="/rest/page/401"/>
17         <!-- Shiro连接约束配置,即过滤链的定义 -->
18         <!-- 下面value值的第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的 -->
19         <!-- anon:它对应的过滤器里面是空的,什么都没做 -->
20         <!-- authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter -->
21         <property name="filterChainDefinitions">
22             <value>
23                 <!-- 静态资源允许访问 -->
24                 /app/** = anon
25                 /hemi/** = anon
26                 /assets/** = anon
27                 <!-- 登录页允许访问 -->
28                 /rest/user/login = anon
29                 <!-- 其他资源需要认证 -->
30                 /** = authc
31             </value>
32         </property>
33     </bean>
34 
35     <!-- 缓存管理器 使用Ehcache实现 -->
36     <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
37         <property name="cacheManagerConfigFile" value="classpath:ehcache-shiro.xml"/>
38     </bean>
39 
40     <!-- 会话DAO -->
41     <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.MemorySessionDAO"/>
42 
43     <!-- 会话管理器 -->
44     <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
45         <property name="sessionDAO" ref="sessionDAO"/>
46     </bean>
47 
48     <!-- 安全管理器 -->
49     <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
50         <property name="realms">
51             <list>
52                 <ref bean="securityRealm"/>
53             </list>
54         </property>
55         <!-- cacheManager,集合spring缓存工厂 -->
56          <property name="cacheManager" ref="shiroEhcacheManager" />
57          <property name="sessionManager" ref="sessionManager" />
58     </bean>
59 
60     <!-- Shiro生命周期处理器 -->
61     <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
62 
63 </beans>
applicationContext-shiro.xml

②ehcache-shiro.xml

 1 <ehcache updateCheck="false" name="shiroCache">
 2 
 3     <defaultCache
 4             maxElementsInMemory="10000"
 5             eternal="false"
 6             timeToIdleSeconds="120"
 7             timeToLiveSeconds="120"
 8             overflowToDisk="false"
 9             diskPersistent="false"
10             diskExpiryThreadIntervalSeconds="120"
11     />
12 </ehcache>
ehcache-shiro.xml

6、配置 Mybatis

mybatis-config.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     <properties>
 7         <property name="dialectClass" value="com.hemi.factor.core.feature.orm.dialect.MySql5Dialect"/>
 8     </properties>
 9 
10     <!-- 配置mybatis的缓存,延迟加载等等一系列属性 -->
11     <settings>
12 
13         <!-- 全局映射器启用缓存 -->
14         <setting name="cacheEnabled" value="true"/>
15 
16         <!-- 查询时,关闭关联对象即时加载以提高性能 -->
17         <setting name="lazyLoadingEnabled" value="true"/>
18 
19         <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
20         <setting name="multipleResultSetsEnabled" value="true"/>
21 
22         <!-- 允许使用列标签代替列名 -->
23         <setting name="useColumnLabel" value="true"/>
24 
25         <!-- 不允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
26         <setting name="useGeneratedKeys" value="false"/>
27 
28         <!-- 给予被嵌套的resultMap以字段-属性的映射支持 FULL,PARTIAL -->
29         <setting name="autoMappingBehavior" value="PARTIAL"/>
30 
31         <!-- 对于批量更新操作缓存SQL以提高性能 BATCH,SIMPLE -->
32         <!-- <setting name="defaultExecutorType" value="BATCH" /> -->
33 
34         <!-- 数据库超过25000秒仍未响应则超时 -->
35         <!-- <setting name="defaultStatementTimeout" value="25000" /> -->
36 
37         <!-- Allows using RowBounds on nested statements -->
38         <setting name="safeRowBoundsEnabled" value="false"/>
39 
40         <!-- Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn. -->
41         <setting name="mapUnderscoreToCamelCase" value="true"/>
42 
43         <!-- MyBatis uses local cache to prevent circular references and speed up repeated nested queries. By default (SESSION) all queries executed during a session are cached. If localCacheScope=STATEMENT 
44             local session will be used just for statement execution, no data will be shared between two different calls to the same SqlSession. -->
45         <setting name="localCacheScope" value="SESSION"/>
46 
47         <!-- Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers require specifying the column JDBC type but others work with generic values 
48             like NULL, VARCHAR or OTHER. -->
49         <setting name="jdbcTypeForNull" value="OTHER"/>
50 
51         <!-- Specifies which Object's methods trigger a lazy load -->
52         <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
53 
54         <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->
55         <setting name="aggressiveLazyLoading" value="false"/>
56 
57     </settings>
58 
59     <typeAliases>
60         <package name="com.hemi.factor.web.model"/>
61         <package name="com.hemi.factor.web.enums"/>
62     </typeAliases>
63 
64     <plugins>
65         <plugin interceptor="com.hemi.factor.core.feature.orm.mybatis.PaginationResultSetHandlerInterceptor"/>
66         <plugin interceptor="com.hemi.factor.core.feature.orm.mybatis.PaginationStatementHandlerInterceptor"/>
67     </plugins>
68 
69 </configuration>
mybatis-config.xml

7、配置Springmvc

  1 <beans xmlns="http://www.springframework.org/schema/beans"
  2        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  3        xmlns:context="http://www.springframework.org/schema/context"
  4        xmlns:mvc="http://www.springframework.org/schema/mvc"
  5        xmlns:aop="http://www.springframework.org/schema/aop"
  6        xsi:schemaLocation="
  7   http://www.springframework.org/schema/beans
  8   http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  9   http://www.springframework.org/schema/context
 10   http://www.springframework.org/schema/context/spring-context-4.1.xsd
 11   http://www.springframework.org/schema/mvc
 12   http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
 13   http://www.springframework.org/schema/aop
 14   http://www.springframework.org/schema/aop/spring-aop-4.1.xsd ">
 15 
 16     <!-- 扫描controller(controller层注入) -->
 17     <context:component-scan base-package="com.hemi.factor.web.controller" use-default-filters="false">
 18         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
 19         <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
 20     </context:component-scan>
 21 
 22     <!-- 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的 -->
 23     <!-- 指定自己定义的validator -->
 24     <!--<mvc:annotation-driven validator="validator"/>-->
 25 
 26     <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
 27 
 28     </bean>
 29     <bean id="webBindingInitializer" class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
 30         <property name="conversionService" ref="conversionService"/>
 31     </bean>
 32     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
 33     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
 34         <property name="webBindingInitializer" ref="webBindingInitializer"/>
 35         <property name="messageConverters">
 36             <list>
 37                 <ref bean="stringConverter" />
 38                 <ref bean="fastjsonConverter" />
 39             </list>
 40         </property>
 41     </bean>
 42     <!--&lt;!&ndash; 以下 validator ConversionService 在使用 mvc:annotation-driven 会 自动注册 &ndash;&gt;-->
 43     <!--<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">-->
 44         <!--<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>-->
 45         <!--&lt;!&ndash; 如果不加默认到 使用classpath下的 ValidationMessages.properties &ndash;&gt;-->
 46         <!--<property name="validationMessageSource" ref="messageSource"/>-->
 47     <!--</bean>-->
 48 
 49     <!--&lt;!&ndash; 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) &ndash;&gt;-->
 50     <!--<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">-->
 51         <!--<property name="basenames">-->
 52             <!--<list>-->
 53                 <!--&lt;!&ndash; 在web环境中一定要定位到classpath 否则默认到当前web应用下找 &ndash;&gt;-->
 54                 <!--<value>classpath:messages</value>-->
 55                 <!--<value>classpath:org/hibernate/validator/ValidationMessages</value>-->
 56             <!--</list>-->
 57         <!--</property>-->
 58         <!--<property name="useCodeAsDefaultMessage" value="false"/>-->
 59         <!--<property name="defaultEncoding" value="UTF-8"/>-->
 60         <!--<property name="cacheSeconds" value="60"/>-->
 61     <!--</bean>-->
 62 
 63     <mvc:interceptors>
 64         <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
 65     </mvc:interceptors>
 66 
 67     <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
 68         <property name="defaultLocale" value="zh_CN"/>
 69     </bean>
 70 
 71     <!-- 改动begin -->
 72     <!-- 解析String请求数据 -->
 73     <bean id="stringConverter"
 74           class="org.springframework.http.converter.StringHttpMessageConverter">
 75         <property name="supportedMediaTypes">
 76             <list>
 77                 <value>text/plain;charset=UTF-8</value>
 78             </list>
 79         </property>
 80     </bean>
 81 
 82 
 83     <!--&lt;!&ndash; 解析json请求数据,将json转换为java对象 &ndash;&gt;-->
 84     <bean id="fastjsonConverter"
 85           class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
 86         <property name="supportedMediaTypes">
 87             <list>
 88                 <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
 89                 <value>text/html;charset=UTF-8</value>
 90                 <value>application/json;charset=UTF-8</value>
 91             </list>
 92         </property>
 93         <property name="features">
 94             <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
 95                 <!-- 空值继续输出 -->
 96                 <value>WriteMapNullValue</value>
 97                 <!-- 防止循环引用 -->
 98                 <value>DisableCircularReferenceDetect</value>
 99                 <!-- 格式化日期,默认格式为:yyyy-MM-dd HH:mm:ss -->
100                 <value>WriteDateUseDateFormat</value>
101             </array>
102         </property>
103     </bean>
104     <!-- 防止循环引用 -->
105     <bean id="DisableCircularReferenceDetect" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
106         <property name="staticField" value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property>
107     </bean>
108 
109     <!-- ContentNegotiatingViewResolver视图解析器,返回多视图 -->
110     <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
111         <property name="order" value="1"/>
112         <!-- 这里是否忽略掉accept header,默认就是false -->
113         <property name="ignoreAcceptHeader" value="true" />
114         <!-- 启用参数支持 -->
115         <property name="favorParameter" value="false"/>
116         <!-- 启用扩展名支持 -->
117         <property name="favorPathExtension" value="true"/>
118         <!-- 如果所有的mediaType都没匹配上,就会使用defaultContentType -->
119         <property name="defaultContentType" value="text/html" />
120 
121         <property name="mediaTypes">
122             <map>
123                 <entry key="json" value="application/json" />
124                 <entry key="xml" value="application/xml" />
125             </map>
126         </property>
127 
128         <property name="defaultViews">
129             <list>
130                 <!-- json视图 -->
131                 <bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView">
132                     <property name="extractValueFromSingleKeyModel" value="true" />
133                     <property name="features">
134                         <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
135                             <!-- 空值继续输出 -->
136                             <value>WriteMapNullValue</value>
137                             <!-- 防止循环引用 -->
138                             <value>DisableCircularReferenceDetect</value>
139                             <!-- 格式化日期,默认格式为:yyyy-MM-dd HH:mm:ss -->
140                             <value>WriteDateUseDateFormat</value>
141                         </array>
142                     </property>
143                 </bean>
144             </list>
145         </property>
146 
147         <property name="viewResolvers">
148             <list>
149                 <!-- 视图解析器,根据视图的名称new ModelAndView(name),在配置文件查找对应的bean配置 -->
150                 <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
151 
152                 <bean
153                         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
154                     <property name="viewClass"
155                               value="org.springframework.web.servlet.view.JstlView" />
156                     <property name="contentType" value="text/html" />
157                     <!-- 对模型视图添加前后缀 -->
158                     <property name="prefix" value="/WEB-INF/views/" />
159                     <property name="suffix" value=".jsp" />
160                 </bean>
161 
162             </list>
163         </property>
164 
165     </bean>
166     <aop:aspectj-autoproxy proxy-target-class="true"/>
167     <mvc:default-servlet-handler/>
168 
169 
170     <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
171     <bean id="multipartResolver"
172           class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
173         <!-- 默认编码 -->
174         <property name="defaultEncoding" value="utf-8" />
175         <!-- 文件大小最大值 -->
176         <property name="maxUploadSize" value="10485760000" />
177         <!-- 内存中的最大值 -->
178         <property name="maxInMemorySize" value="40960" />
179     </bean>
180 
181 
182     <!--开启AOP,对类代理-->
183     <aop:config proxy-target-class="true"/>
184     <!-- 启用shrio授权注解拦截方式 -->
185     <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
186         <property name="securityManager" ref="securityManager"/>
187     </bean>
188 
189 </beans>
spring-mvc.xml

8、其他

①messages.properties

1 #user
2 user.username.null=用户名不能为空
3 user.password.null=密码不能为空
messages.properties

②log4j.properties

 1 # DEBUG,INFO,WARN,ERROR,FATAL
 2 LOG_LEVEL=INFO
 3 
 4 log4j.rootLogger=${LOG_LEVEL},CONSOLE,FILE
 5 
 6 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
 7 log4j.appender.CONSOLE.Encoding=utf-8
 8 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
 9 #log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} %C{8}@(%F:%L):%m%n 
10 log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} %C{1}@(%F:%L):%m%n
11 
12 log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
13 log4j.appender.FILE.File=${catalina.base}/logs/factor.log
14 log4j.appender.FILE.Encoding=utf-8
15 log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
16 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
17 #log4j.appender.FILE.layout=org.apache.log4j.HTMLLayout
18 log4j.appender.FILE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss} %C{8}@(%F\:%L)\:%m%n 
log4j.properties

③factor.sql

  1 CREATE DATABASE factor;
  2 
  3 DROP TABLE IF EXISTS `sys_permission`;
  4 CREATE TABLE `sys_permission` (
  5   `id` bigint(20) NOT NULL COMMENT '主键',
  6   `name` varchar(128) NOT NULL COMMENT '资源名称',
  7   `type` varchar(32) NOT NULL COMMENT '资源类型:menu,button,',
  8   `url` varchar(128) DEFAULT NULL COMMENT '访问url地址',
  9   `percode` varchar(128) DEFAULT NULL COMMENT '权限代码字符串',
 10   `parentid` bigint(20) DEFAULT NULL COMMENT '父结点id',
 11   `parentids` varchar(128) DEFAULT NULL COMMENT '父结点id列表串',
 12   `sortstring` varchar(128) DEFAULT NULL COMMENT '排序号',
 13   `available` char(1) DEFAULT NULL COMMENT '是否可用,1:可用,0不可用',
 14   `icon` varchar(128) DEFAULT NULL COMMENT '图标',
 15   `style` varchar(128) DEFAULT NULL COMMENT '样式',
 16   `obiligate` varchar(128) DEFAULT NULL COMMENT '预留字段',
 17   PRIMARY KEY (`id`)
 18 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 19 
 20 -- ----------------------------
 21 -- Records of sys_permission
 22 -- ----------------------------
 23 INSERT INTO `sys_permission` VALUES ('1', '权限', '', '', 'user:create', '0', '0/', '0', '1', null, null, null);
 24 INSERT INTO `sys_permission` VALUES ('10', '用户界面', 'menu', null, 'super_admin', null, null, null, null, 'fa fa-rss-square', null, null);
 25 INSERT INTO `sys_permission` VALUES ('11', '界面1', 'menu', null, 'user:create', '10', '11', null, null, null, null, null);
 26 INSERT INTO `sys_permission` VALUES ('12', '界面2', 'menu', null, 'user:create', '10', '12', null, null, null, null, null);
 27 INSERT INTO `sys_permission` VALUES ('30', '系统管理', 'menu', null, 'super_admin', null, null, null, null, 'fa fa-gears', null, null);
 28 INSERT INTO `sys_permission` VALUES ('31', '商品管理', 'menu', '/item/queryItem.action', 'user:create', '30', '31', '1.', '1', null, null, null);
 29 INSERT INTO `sys_permission` VALUES ('32', '用户管理', 'menu', '/user/query.action', 'super_admin', '30', '32', '2.', '1', null, null, null);
 30 INSERT INTO `sys_permission` VALUES ('33', '权限管理', 'menu', null, 'super_admin', '30', '33', null, null, null, null, null);
 31 INSERT INTO `sys_permission` VALUES ('50', '个人中心', 'menu', null, 'user:create', null, null, null, '1', 'fa fa-user', null, null);
 32 INSERT INTO `sys_permission` VALUES ('51', '信息修改', 'menu', null, 'user:create', '50', '51', null, '1', null, null, null);
 33 INSERT INTO `sys_permission` VALUES ('52', '密码修改', 'menu', null, 'user:create', '50', '52', null, null, null, null, null);
 34 INSERT INTO `sys_permission` VALUES ('112', '商品新增', 'permission', '/item/add.action', 'item:create', '11', '0/1/11/', '', '1', null, null, null);
 35 INSERT INTO `sys_permission` VALUES ('113', '商品修改', 'permission', '/item/editItem.action', 'item:update', '11', '0/1/11/', '', '1', null, null, null);
 36 INSERT INTO `sys_permission` VALUES ('114', '商品删除', 'permission', '', 'item:delete', '11', '0/1/11/', '', '1', null, null, null);
 37 INSERT INTO `sys_permission` VALUES ('115', '商品查询', 'permission', '/item/queryItem.action', 'item:query', '11', '0/1/15/', null, '1', null, null, null);
 38 INSERT INTO `sys_permission` VALUES ('212', '用户新增', 'permission', '', 'user:create', '21', '0/1/21/', '', '1', null, null, null);
 39 INSERT INTO `sys_permission` VALUES ('213', '用户修改', 'permission', '', 'user:update', '21', '0/1/21/', '', '1', null, null, null);
 40 INSERT INTO `sys_permission` VALUES ('214', '用户删除', 'permission', '', 'user:delete', '21', '0/1/21/', '', '1', null, null, null);
 41 
 42 -- ----------------------------
 43 -- Table structure for sys_role
 44 -- ----------------------------
 45 DROP TABLE IF EXISTS `sys_role`;
 46 CREATE TABLE `sys_role` (
 47   `id` varchar(36) NOT NULL,
 48   `name` varchar(128) NOT NULL,
 49   `available` char(1) DEFAULT NULL COMMENT '是否可用,1:可用,0不可用',
 50   PRIMARY KEY (`id`)
 51 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 52 
 53 -- ----------------------------
 54 -- Records of sys_role
 55 -- ----------------------------
 56 INSERT INTO `sys_role` VALUES ('admin', '管理员', '1');
 57 INSERT INTO `sys_role` VALUES ('superadmin', '超级管理员', '1');
 58 INSERT INTO `sys_role` VALUES ('user', '普通用户', '1');
 59 INSERT INTO `sys_role` VALUES ('vipuser', 'VIP用户', '1');
 60 
 61 -- ----------------------------
 62 -- Table structure for sys_role_permission
 63 -- ----------------------------
 64 DROP TABLE IF EXISTS `sys_role_permission`;
 65 CREATE TABLE `sys_role_permission` (
 66   `id` varchar(36) NOT NULL,
 67   `sys_role_id` varchar(32) NOT NULL COMMENT '角色id',
 68   `sys_permission_id` varchar(32) NOT NULL COMMENT '权限id',
 69   PRIMARY KEY (`id`)
 70 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 71 
 72 -- ----------------------------
 73 -- Records of sys_role_permission
 74 -- ----------------------------
 75 INSERT INTO `sys_role_permission` VALUES ('rp01', 'admin', '10');
 76 INSERT INTO `sys_role_permission` VALUES ('rp02', 'admin', '11');
 77 INSERT INTO `sys_role_permission` VALUES ('rp03', 'admin', '12');
 78 INSERT INTO `sys_role_permission` VALUES ('rp04', 'admin', '30');
 79 INSERT INTO `sys_role_permission` VALUES ('rp05', 'admin', '31');
 80 INSERT INTO `sys_role_permission` VALUES ('rp06', 'admin', '32');
 81 INSERT INTO `sys_role_permission` VALUES ('rp07', 'admin', '33');
 82 INSERT INTO `sys_role_permission` VALUES ('rp08', 'admin', '50');
 83 INSERT INTO `sys_role_permission` VALUES ('rp09', 'admin', '51');
 84 INSERT INTO `sys_role_permission` VALUES ('rp10', 'admin', '52');
 85 INSERT INTO `sys_role_permission` VALUES ('rp11', 'user', '10');
 86 INSERT INTO `sys_role_permission` VALUES ('rp12', 'user', '11');
 87 INSERT INTO `sys_role_permission` VALUES ('rp13', 'user', '12');
 88 INSERT INTO `sys_role_permission` VALUES ('rp14', 'user', '50');
 89 INSERT INTO `sys_role_permission` VALUES ('rp15', 'user', '51');
 90 INSERT INTO `sys_role_permission` VALUES ('rp16', 'user', '52');
 91 
 92 -- ----------------------------
 93 -- Table structure for sys_user
 94 -- ----------------------------
 95 DROP TABLE IF EXISTS `sys_user`;
 96 CREATE TABLE `sys_user` (
 97   `id` varchar(36) NOT NULL COMMENT '主键',
 98   `usercode` varchar(32) NOT NULL COMMENT '账号',
 99   `username` varchar(64) NOT NULL COMMENT '姓名',
100   `password` varchar(32) NOT NULL COMMENT '密码',
101   `salt` varchar(64) DEFAULT NULL COMMENT '',
102   `locked` char(1) DEFAULT NULL COMMENT '账号是否锁定,1:锁定,0未锁定',
103   PRIMARY KEY (`id`)
104 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
105 
106 -- ----------------------------
107 -- Records of sys_user
108 -- ----------------------------
109 INSERT INTO `sys_user` VALUES ('ua01', 'admin', '佟掌柜', '123456', 'uiwueylm', '0');
110 INSERT INTO `sys_user` VALUES ('ut01', 'user', '小鱼儿', '123456', 'sdfafd', '0');
111 
112 -- ----------------------------
113 -- Table structure for sys_user_role
114 -- ----------------------------
115 DROP TABLE IF EXISTS `sys_user_role`;
116 CREATE TABLE `sys_user_role` (
117   `id` varchar(36) NOT NULL,
118   `sys_user_id` varchar(32) NOT NULL,
119   `sys_role_id` varchar(32) NOT NULL,
120   PRIMARY KEY (`id`)
121 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
122 
123 -- ----------------------------
124 -- Records of sys_user_role
125 -- ----------------------------
126 INSERT INTO `sys_user_role` VALUES ('ur01', 'ua01', 'admin');
127 INSERT INTO `sys_user_role` VALUES ('ur02', 'ut01', 'user');
factor.sql

 

 

THE END.

 

posted @ 2016-12-21 23:17  日青天  阅读(3986)  评论(5编辑  收藏  举报