关闭

Spring,SpringMvc,Myabtis整合

797人阅读 评论(0) 收藏 举报
分类:



源码地址:https://github.com/starzou/quick4j 点击打开


看我们的项目结构:


是一个典型的Maven 项目 :

src/main/Java:存放java源文件
src/main/resources:存放程序资源、配置文件
src/test/java:存放测试代码文件
src/main/webapp:web根目录
pom.xml : maven项目配置文件,管理依赖,编译,打包


主要的后端架构:spring + Spring MVC + Mybatis + Apache Shiro

前端界面主要使用MetroNic 模板,


先看我们搭建完成,跑起来的效果,这样你才有兴趣看下去:




你可以 在github 上 checkout quick4j项目 查看 ,并跟下面步骤 来搭建:

强烈建议你,checkout  https://github.com/starzou/quick4j ,在本地跑起来,再试着自己搭建框架


1、首先创建 maven 项目 ,用 idea 、eclipse 或 mvn 命令行都行 

2、配置 pom.xml ,添加框架依赖

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


3、配置web.xml

web.xml是一个项目的核心,看看它的一些配置:
配置 ContextLoaderListener 监听器
配置Spring字符编码过滤器
配置shiro 安全过滤器
配置Spring MVC 核心控制器 DispatcherServlet
配置一些页面

spring 和 apache shiro 是由一个 ContextLoaderListener 监听器 加载的配置文件,并初始化

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.     <filter>  
  39.         <filter-name>shiroFilter</filter-name>  
  40.         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
  41.         <async-supported>true</async-supported>  
  42.         <init-param>  
  43.             <param-name>targetFilterLifecycle</param-name>  
  44.             <param-value>true</param-value>  
  45.         </init-param>  
  46.     </filter>  
  47.     <filter-mapping>  
  48.         <filter-name>shiroFilter</filter-name>  
  49.         <url-pattern>/*</url-pattern>  
  50.     </filter-mapping>  
  51.   
  52.     <!-- 配置log4j配置文件路径 -->  
  53.     <context-param>  
  54.         <param-name>log4jConfigLocation</param-name>  
  55.         <param-value>classpath:log4j.properties</param-value>  
  56.     </context-param>  
  57.     <!-- 60s 检测日志配置 文件变化 -->  
  58.     <context-param>  
  59.         <param-name>log4jRefreshInterval</param-name>  
  60.         <param-value>60000</param-value>  
  61.     </context-param>  
  62.   
  63.     <!-- 配置Log4j监听器 -->  
  64.     <listener>  
  65.         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
  66.     </listener>  
  67.   
  68.     <!-- Spring MVC 核心控制器 DispatcherServlet 配置 -->  
  69.     <servlet>  
  70.         <servlet-name>dispatcher</servlet-name>  
  71.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  72.         <init-param>  
  73.             <param-name>contextConfigLocation</param-name>  
  74.             <param-value>classpath*:spring-mvc.xml</param-value>  
  75.         </init-param>  
  76.         <load-on-startup>1</load-on-startup>  
  77.     </servlet>  
  78.     <servlet-mapping>  
  79.         <servlet-name>dispatcher</servlet-name>  
  80.         <!-- 拦截所有/rest/* 的请求,交给DispatcherServlet处理,性能最好 -->  
  81.         <url-pattern>/rest/*</url-pattern>  
  82.     </servlet-mapping>  
  83.   
  84.     <!-- 首页 -->  
  85.     <welcome-file-list>  
  86.         <welcome-file>rest/index</welcome-file>  
  87.     </welcome-file-list>  
  88.   
  89.     <!-- 错误页 -->  
  90.     <error-page>  
  91.         <error-code>404</error-code>  
  92.         <location>/rest/page/404</location>  
  93.     </error-page>  
  94.     <error-page>  
  95.         <error-code>500</error-code>  
  96.         <location>/rest/page/500</location>  
  97.     </error-page>  
  98.     <error-page>  
  99.         <exception-type>org.apache.shiro.authz.AuthorizationException</exception-type>  
  100.         <location>/rest/page/401</location>  
  101.     </error-page>  
  102.   
  103. </web-app>  


4、spring配置:

applicationContext.xml

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.eliteams.quick4j"></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/eliteams/quick4j/web/dao/*.xml"/>  
  73.   
  74.     <!-- spring与mybatis整合配置,扫描所有dao -->  
  75.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.eliteams.quick4j.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.eliteams.quick4j.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>  

application.properties

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. ##JDBC Global Setting  
  2. jdbc.driver=com.mysql.jdbc.Driver  
  3. jdbc.url=jdbc:mysql://localhost:3306/quick4j?useUnicode=true&characterEncoding=utf-8  
  4. jdbc.username=root  
  5. jdbc.password=admin123  
  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  


ehcache.xml

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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>  

5、Apache Shiro 配置 : 要配置realms bean

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.         <property name="securityManager" ref="securityManager"/>  
  12.         <property name="loginUrl" value="/rest/page/login"/>  
  13.         <property name="successUrl" value="/rest/index"/>  
  14.         <property name="unauthorizedUrl" value="/rest/page/401"/>  
  15.         <property name="filterChainDefinitions">  
  16.             <value>  
  17.                 <!-- 静态资源允许访问 -->  
  18.                 /app/** = anon  
  19.                 /assets/** = anon  
  20.                 <!-- 登录页允许访问 -->  
  21.                 /rest/user/login = anon  
  22.                 <!-- 其他资源需要认证 -->  
  23.                 /** = authc  
  24.             </value>  
  25.         </property>  
  26.     </bean>  
  27.   
  28.     <!-- 缓存管理器 使用Ehcache实现 -->  
  29.     <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">  
  30.         <property name="cacheManagerConfigFile" value="classpath:ehcache-shiro.xml"/>  
  31.     </bean>  
  32.   
  33.     <!-- 会话DAO -->  
  34.     <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.MemorySessionDAO"/>  
  35.   
  36.     <!-- 会话管理器 -->  
  37.     <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">  
  38.         <property name="sessionDAO" ref="sessionDAO"/>  
  39.     </bean>  
  40.   
  41.     <!-- 安全管理器 -->  
  42.     <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">  
  43.         <property name="realms">  
  44.             <list>  
  45.                 <ref bean="securityRealm"/>  
  46.             </list>  
  47.         </property>  
  48.         <!-- cacheManager,集合spring缓存工厂 -->  
  49.         <!-- <property name="cacheManager" ref="shiroEhcacheManager" /> -->  
  50.         <!-- <property name="sessionManager" ref="sessionManager" /> -->  
  51.     </bean>  
  52.   
  53.     <!-- Shiro生命周期处理器 -->  
  54.     <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>  
  55.   
  56. </beans>  

ehcache-shiro.xml

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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>  


6、MyBatis 配置

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.eliteams.quick4j.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.eliteams.quick4j.web.model"/>  
  61.         <package name="com.eliteams.quick4j.web.enums"/>  
  62.     </typeAliases>  
  63.   
  64.     <plugins>  
  65.         <plugin interceptor="com.eliteams.quick4j.core.feature.orm.mybatis.PaginationResultSetHandlerInterceptor"/>  
  66.         <plugin interceptor="com.eliteams.quick4j.core.feature.orm.mybatis.PaginationStatementHandlerInterceptor"/>  
  67.     </plugins>  
  68.   
  69. </configuration>  



7、Spring MVC 配置

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:aop="http://www.springframework.org/schema/aop"  
  4.        xmlns:context="http://www.springframework.org/schema/context"  
  5.        xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.        xmlns:tx="http://www.springframework.org/schema/tx"  
  7.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  8.        xmlns:p="http://www.springframework.org/schema/p"  
  9.        xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd  
  10.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
  11.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd   
  12.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd   
  13.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">  
  14.   
  15.     <!-- 扫描controller(controller层注入) -->  
  16.     <context:component-scan base-package="com.eliteams.quick4j.web.controller"/>  
  17.   
  18.     <!-- 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的 -->  
  19.     <!-- 指定自己定义的validator -->  
  20.     <mvc:annotation-driven validator="validator"/>  
  21.   
  22.     <!-- 以下 validator ConversionService 在使用 mvc:annotation-driven 会 自动注册 -->  
  23.     <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">  
  24.         <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>  
  25.         <!-- 如果不加默认到 使用classpath下的 ValidationMessages.properties -->  
  26.         <property name="validationMessageSource" ref="messageSource"/>  
  27.     </bean>  
  28.   
  29.     <!-- 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) -->  
  30.     <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  
  31.         <property name="basenames">  
  32.             <list>  
  33.                 <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找 -->  
  34.                 <value>classpath:messages</value>  
  35.                 <value>classpath:org/hibernate/validator/ValidationMessages</value>  
  36.             </list>  
  37.         </property>  
  38.         <property name="useCodeAsDefaultMessage" value="false"/>  
  39.         <property name="defaultEncoding" value="UTF-8"/>  
  40.         <property name="cacheSeconds" value="60"/>  
  41.     </bean>  
  42.   
  43.     <mvc:interceptors>  
  44.         <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>  
  45.     </mvc:interceptors>  
  46.   
  47.     <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">  
  48.         <property name="defaultLocale" value="zh_CN"/>  
  49.     </bean>  
  50.   
  51.     <!-- 支持返回json(避免IE在ajax请求时,返回json出现下载 ) -->  
  52.     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  53.         <property name="messageConverters">  
  54.             <list>  
  55.                 <ref bean="mappingJacksonHttpMessageConverter"/>  
  56.             </list>  
  57.         </property>  
  58.     </bean>  
  59.     <bean id="mappingJacksonHttpMessageConverter"  
  60.           class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
  61.         <property name="supportedMediaTypes">  
  62.             <list>  
  63.                 <value>text/plain;charset=UTF-8</value>  
  64.                 <value>application/json;charset=UTF-8</value>  
  65.             </list>  
  66.         </property>  
  67.     </bean>  
  68.     <!-- 支持返回json -->  
  69.   
  70.     <!-- 对模型视图添加前后缀 -->  
  71.     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"  
  72.           p:prefix="/WEB-INF/views/" p:suffix=".jsp"/>  
  73.   
  74.     <!-- 配置springMVC处理上传文件的信息 -->  
  75.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
  76.         <property name="defaultEncoding" value="utf-8"/>  
  77.         <property name="maxUploadSize" value="10485760000"/>  
  78.         <property name="maxInMemorySize" value="40960"/>  
  79.     </bean>  
  80.   
  81.     <!-- 启用shrio授权注解拦截方式 -->  
  82.     <aop:config proxy-target-class="true"></aop:config>  
  83.     <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">  
  84.         <property name="securityManager" ref="securityManager"/>  
  85.     </bean>  
  86.   
  87. </beans>  


messages.properties : hibernate-validator 配置文件,国际化资源文件

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. #user  
  2. user.username.null=用户名不能为空  
  3. user.password.null=密码不能为空  

log4j.properties : 

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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/quick4j.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   

quick4j.sql

  1. /*  
  2. SQLyog 企业版 - MySQL GUI v8.14   
  3. MySQL - 5.5.27 : Database - quick4j  
  4. *********************************************************************  
  5. */  
  6.   
  7.   
  8. /*!40101 SET NAMES utf8 */;  
  9.   
  10. /*!40101 SET SQL_MODE=''*/;  
  11.   
  12. /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;  
  13. /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;  
  14. /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;  
  15. /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;  
  16. CREATE DATABASE /*!32312 IF NOT EXISTS*/`quick4j` /*!40100 DEFAULT CHARACTER SET utf8 */;  
  17.   
  18. USE `quick4j`;  
  19.   
  20. /*Table structure for table `permission` */  
  21.   
  22. DROP TABLE IF EXISTS `permission`;  
  23.   
  24. CREATE TABLE `permission` (  
  25.   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '权限id',  
  26.   `permission_name` varchar(32) DEFAULT NULL COMMENT '权限名',  
  27.   `permission_sign` varchar(128) DEFAULT NULL COMMENT '权限标识,程序中判断使用,如"user:create"',  
  28.   `description` varchar(256) DEFAULT NULL COMMENT '权限描述,UI界面显示使用',  
  29.   PRIMARY KEY (`id`)  
  30. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='权限表';  
  31.   
  32. /*Data for the table `permission` */  
  33.   
  34. insert  into `permission`(`id`,`permission_name`,`permission_sign`,`description`) values (1,'用户新增','user:create',NULL);  
  35.   
  36. /*Table structure for table `role` */  
  37.   
  38. DROP TABLE IF EXISTS `role`;  
  39.   
  40. CREATE TABLE `role` (  
  41.   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '角色id',  
  42.   `role_name` varchar(32) DEFAULT NULL COMMENT '角色名',  
  43.   `role_sign` varchar(128) DEFAULT NULL COMMENT '角色标识,程序中判断使用,如"admin"',  
  44.   `description` varchar(256) DEFAULT NULL COMMENT '角色描述,UI界面显示使用',  
  45.   PRIMARY KEY (`id`)  
  46. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='角色表';  
  47.   
  48. /*Data for the table `role` */  
  49.   
  50. insert  into `role`(`id`,`role_name`,`role_sign`,`description`) values (1,'admin','admin','管理员');  
  51.   
  52. /*Table structure for table `role_permission` */  
  53.   
  54. DROP TABLE IF EXISTS `role_permission`;  
  55.   
  56. CREATE TABLE `role_permission` (  
  57.   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id',  
  58.   `role_id` bigint(20) unsigned DEFAULT NULL COMMENT '角色id',  
  59.   `permission_id` bigint(20) unsigned DEFAULT NULL COMMENT '权限id',  
  60.   PRIMARY KEY (`id`)  
  61. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='角色与权限关联表';  
  62.   
  63. /*Data for the table `role_permission` */  
  64.   
  65. insert  into `role_permission`(`id`,`role_id`,`permission_id`) values (1,2,1);  
  66.   
  67. /*Table structure for table `user` */  
  68.   
  69. DROP TABLE IF EXISTS `user`;  
  70.   
  71. CREATE TABLE `user` (  
  72.   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户id',  
  73.   `username` varchar(50) DEFAULT NULL COMMENT '用户名',  
  74.   `passwordchar(64) DEFAULT NULL COMMENT '密码',  
  75.   `state` varchar(32) DEFAULT NULL COMMENT '状态',  
  76.   `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
  77.   PRIMARY KEY (`id`)  
  78. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='用户表';  
  79.   
  80. /*Data for the table `user` */  
  81.   
  82. insert  into `user`(`id`,`username`,`password`,`state`,`create_time`) values (1,'starzou','8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92',NULL,'2014-07-17 12:59:08');  
  83.   
  84. /*Table structure for table `user_role` */  
  85.   
  86. DROP TABLE IF EXISTS `user_role`;  
  87.   
  88. CREATE TABLE `user_role` (  
  89.   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id',  
  90.   `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户id',  
  91.   `role_id` bigint(20) unsigned DEFAULT NULL COMMENT '角色id',  
  92.   PRIMARY KEY (`id`)  
  93. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='用户与角色关联表';  
  94.   
  95. /*Data for the table `user_role` */  
  96.   
  97. insert  into `user_role`(`id`,`user_id`,`role_id`) values (1,1,1);  
  98.   
  99. /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;  
  100. /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;  
  101. /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;  
  102. /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:61621次
    • 积分:906
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:99篇
    • 译文:0篇
    • 评论:4条
    最新评论