1. <wbr id="m8vu6"></wbr>

      <del id="m8vu6"><center id="m8vu6"><source id="m8vu6"></source></center></del>
        <p id="m8vu6"><sub id="m8vu6"></sub></p>

        VB.net 2010 視頻教程 VB.net 2010 視頻教程 VB.net 2010 視頻教程
        SQL Server 2008 視頻教程 c#入門經典教程 Visual Basic從門到精通視頻教程
        當前位置:
        首頁 > 編程開發 > Java教程 >
        • java教程之利用idea創建一個基本的smm項目(帶增刪

        • 2019-06-10 22:44 來源:未知

        環境  idea  jdk1.8  tomcat  mysql

        打開idea選擇創建一個maven項目

        然后點擊next,next,finsh

        然后看項目的結構

        如圖所示

        接著創建com包,再在com包下新建四個包,分別命名為:

         

        自定義pom.xml

        復制代碼
        <?xml version="1.0" encoding="UTF-8"?>
        
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
         <modelVersion>4.0.0</modelVersion>
        
         <groupId>com.li</groupId>
         <artifactId>ssm_test_2</artifactId>
         <version>1.0-SNAPSHOT</version>
         <packaging>war</packaging>
        
         <name>ssm_test_2 Maven Webapp</name>
         <!-- 用來設置版本號 -->
         <properties>
           <srping.version>4.0.2.RELEASE</srping.version>
           <mybatis.version>3.2.8</mybatis.version>
           <slf4j.version>1.7.12</slf4j.version>
           <log4j.version>1.2.17</log4j.version>
           <druid.version>1.0.9</druid.version>
         </properties>
         <!-- 用到的jar包 -->
         <dependencies>
           <!-- servlet依賴的jar包start -->
           <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>javax.servlet-api</artifactId>
           </dependency>
           <!-- servlet依賴的jar包start -->
        
           <!-- jsp依賴jar包start -->
           <dependency>
             <groupId>javax.servlet.jsp</groupId>
             <artifactId>javax.servlet.jsp-api</artifactId>
             <version>2.3.1</version>
           </dependency>
           <!-- 單元測試 -->
           <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.11</version>
             <!-- 表示開發的時候引入,發布的時候不會加載此包 -->
             <scope>test</scope>
           </dependency>
        
           <!-- spring框架包 -->
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-oxm</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-tx</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jdbc</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-aop</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context-support</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-expression</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-orm</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
             <version>${srping.version}</version>
           </dependency>
           <!-- spring框架包 -->
           <!-- mybatis框架包 -->
           <dependency>
             <groupId>org.mybatis</groupId>
             <artifactId>mybatis</artifactId>
             <version>${mybatis.version}</version>
           </dependency>
           <dependency>
             <groupId>org.mybatis</groupId>
             <artifactId>mybatis-spring</artifactId>
             <version>1.2.2</version>
           </dependency>
           <!-- mybatis框架包 -->
           <!-- 數據庫驅動 -->
           <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>5.1.35</version>
           </dependency>
           <!-- 導入dbcp的jar包,用來在applicationContext.xml中配置數據庫 -->
           <dependency>
             <groupId>commons-dbcp</groupId>
             <artifactId>commons-dbcp</artifactId>
             <version>1.2.2</version>
           </dependency>
           <!-- jstl標簽類 -->
           <dependency>
             <groupId>jstl</groupId>
             <artifactId>jstl</artifactId>
             <version>1.2</version>
           </dependency>
           <!-- log -->
           <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
             <version>${log4j.version}</version>
           </dependency>
           <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>${slf4j.version}</version>
           </dependency>
           <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
             <version>${slf4j.version}</version>
           </dependency>
           <!-- 連接池 -->
           <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>druid</artifactId>
             <version>${druid.version}</version>
           </dependency>
         </dependencies>
        
         <build>
           <!-- 如果不添加此節點mybatis的mapper.xml文件都會被漏掉。 -->
           <resources>
             <resource>
               <directory>src/main/java</directory>
               <includes>
                 <include>**/*.properties</include>
                 <include>**/*.xml</include>
               </includes>
               <filtering>false</filtering>
             </resource>
             <resource>
               <directory>src/main/resources</directory>
               <includes>
                 <include>**/*.properties</include>
                 <include>**/*.xml</include>
               </includes>
               <filtering>false</filtering>
             </resource>
           </resources>
           <!-- java編譯插件,如果maven的設置里配置好jdk版本就不用 -->
           <plugins>
             <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>3.2</version>
               <configuration>
                 <source>1.8</source>
                 <target>1.8</target>
                 <encoding>UTF-8</encoding>
               </configuration>
             </plugin>
           </plugins>
         </build>
        </project>
        復制代碼

        在resource包下新建Directory:mapper(用來放xxMapper.xml)

        添加jdbc.properties和lo4j.properties文件

        jdbc.properties

        復制代碼
        driver=com.mysql.jdbc.Driver
        url=jdbc\:mysql\://localhost\:3306/test
        username=root
        password=123456
        
        initialSize=0
        
        maxActive=20
        
        maxIdle=20
        
        minIdle=1
        
        maxWait=60000
        復制代碼

        lo4j.properties文件

        復制代碼
        log4j.rootLogger=DEBUG,CONSOLE,file
        #log4j.rootLogger=ERROR,ROLLING_FILE
        log4j.logger.com.qhit.dao=debug
        log4j.logger.com.ibatis=debug
        log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
        log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
        log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
        log4j.logger.java.sql.Connection=debug
        log4j.logger.java.sql.Statement=debug
        log4j.logger.java.sql.PreparedStatement=debug
        log4j.logger.java.sql.ResultSet=debug
        log4j.logger.org.tuckey.web.filters.urlrewrite.UrlRewriteFilter=debug
        
        ######################################################################################
        # Console Appender  日志在控制輸出配置
        ######################################################################################
        log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
        log4j.appender.Threshold=error
        log4j.appender.CONSOLE.Target=System.out
        log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
        log4j.appender.CONSOLE.layout.ConversionPattern= [%p] %d %c - %m%n
        
        
        ######################################################################################
        # DailyRolling File  每天產生一個日志文件,文件名格式:log2009-09-11
        ######################################################################################
        log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
        log4j.appender.file.DatePattern=yyyy-MM-dd
        log4j.appender.file.File=log.log
        log4j.appender.file.Append=true
        log4j.appender.file.Threshold=error
        log4j.appender.file.layout=org.apache.log4j.PatternLayout
        log4j.appender.file.layout.ConversionPattern=%d{yyyy-M-d HH:mm:ss}%x[%5p](%F:%L) %m%n
        
        
        log4j.logger.com.opensymphony.xwork2=error  
        復制代碼

         

        然后創建applicationContext.xm

        復制代碼
        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                               http://www.springframework.org/schema/tx
                               http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        
          <!-- 加載properties文件 -->
          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
             <property name="location" value="classpath:jdbc.properties"/>
          </bean>
        
          <!-- 配置數據源 -->
          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
             <property name="driverClassName" value="${driver}"/>
             <property name="url" value="${url}"/>
             <property name="username" value="${username}"/>
             <property name="password" value="${password}"/>
          </bean>
        
          <!-- mybatis和spring完美整合,不需要mybatis的配置映射文件 -->
          <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
             <property name="dataSource" ref="dataSource"/>
             <!-- 掃描model包 -->
             <property name="typeAliasesPackage" value="com.lwy.pojo"/>
             <!-- 掃描sql配置文件:mapper需要的xml文件-->
             <property name="mapperLocations" value="classpath:mapper/*.xml"/>
          </bean>
        
          <!-- Mapper動態代理開發,掃描dao接口包-->
          <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
             <!-- 注入sqlSessionFactory -->
             <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
             <!-- 給出需要掃描Dao接口包 -->
             <property name="basePackage" value="com.lwy.mapper"/>
          </bean>
        
          <!-- 事務管理 -->
          <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             <!--數據庫連接池-->
             <property name="dataSource" ref="dataSource"/>
          </bean>
        </beans>
        復制代碼

        創建sping-mvc.xml

        復制代碼
        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:context="http://www.springframework.org/schema/context"
             xmlns:mvc="http://www.springframework.org/schema/mvc"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/mvc
              http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
        
          <!-- 掃描注解,這樣com.xjt包下的文件都能被掃描 -->
          <context:component-scan base-package="com.lwy"/>
        
          <!-- 開啟SpringMVC注解模式 -->
          <mvc:annotation-driven/>
        
          <!-- 靜態資源默認servlet配置 -->
          <mvc:default-servlet-handler/>
        
          <!-- 配置返回視圖的路徑,以及識別后綴是jsp文件 -->
          <bean class
              
        
        
        
          
        免费看成年人视频大全_免费看成年人视频在线观看