91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ssm框架如何使用IDEA搭建

發布時間:2020-11-04 16:56:46 來源:億速云 閱讀:242 作者:Leah 欄目:開發技術

ssm框架如何使用IDEA搭建?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

ssm(spring springMVC mybatis)

1.創建項目

file->new->project

ssm框架如何使用IDEA搭建
ssm框架如何使用IDEA搭建
ssm框架如何使用IDEA搭建

2.新建的maven項目目錄結構

ssm框架如何使用IDEA搭建

添加ssm需要的文件夾等

ssm框架如何使用IDEA搭建

如果去掉java文件夾的藍色標志,會發現這里new時不能創建java類或包

ssm框架如何使用IDEA搭建

ssm框架如何使用IDEA搭建

如果main/java前不是藍色文件夾或test/java前不是綠色文件夾,可以這樣添加

ssm框架如何使用IDEA搭建

ssm框架如何使用IDEA搭建

3.加入maven依賴

pom.xml

<&#63;xml version="1.0" encoding="UTF-8"&#63;>

<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>org.example</groupId>
 <artifactId>ssm3</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>war</packaging>

 <name>ssm3 Maven Webapp</name>
 <!-- FIXME change it to the project's website -->
 <url>http://www.example.com</url>

 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <maven.compiler.source>1.7</maven.compiler.source>
 <maven.compiler.target>1.7</maven.compiler.target>
 <jackson.version>2.5.4</jackson.version>
 </properties>

 <dependencies>

 <!-- controller返回json -->
 <dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>${jackson.version}</version>
 </dependency>

 <dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>${jackson.version}</version>
 </dependency>

 <!-- 引入spring mvc的jar包 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>

 <!-- JDBC支持包,包括數據源設置和JDBC訪問支持 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>


 <!-- Spring提供對AspectJ框架的整合 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>


 <!-- mybatis依賴包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
 <dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis</artifactId>
  <version>3.4.2</version>
 </dependency>


 <!-- mybatis引入spring適配包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
 <dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>1.3.1</version>
 </dependency>


 <!-- 數據庫連接池 c3p0 -->
 <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
 <dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
 </dependency>


 <!-- mysql驅動 -->
 <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
 <dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.13</version>
 </dependency>

 <!-- jstl標簽相關的包 -->
 <!-- https://mvnrepository.com/artifact/jstl/jstl -->
 <dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
 </dependency>


 <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
 <dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
 </dependency>


 <!-- 逆向工程jar包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
 <dependency>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-core</artifactId>
  <version>1.3.5</version>
 </dependency>


 <!--分頁依賴的jar包-->
 <dependency>
  <groupId>com.github.pagehelper</groupId>
  <artifactId>pagehelper</artifactId>
  <version>5.0.0</version>
 </dependency>

 </dependencies>

 <build>
 <finalName>ssm3</finalName>
 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  <plugins>
  <plugin>
   <artifactId>maven-clean-plugin</artifactId>
   <version>3.1.0</version>
  </plugin>
  <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
  <plugin>
   <artifactId>maven-resources-plugin</artifactId>
   <version>3.0.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.8.0</version>
  </plugin>
  <plugin>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.22.1</version>
  </plugin>
  <plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>3.2.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-install-plugin</artifactId>
   <version>2.5.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.8.2</version>
  </plugin>
  </plugins>
 </pluginManagement>
 </build>
</project>

ssm框架如何使用IDEA搭建

4.加入spring配置文件(applicationContext.xml)

ssm框架如何使用IDEA搭建

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  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/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


 <!-- spring 配置文件 主要配置和業務邏輯有關的 -->

 <!-- 配置數據庫連接的相關信息 dbconfig.properties也定義在resources文件夾下-->
 <context:property-placeholder location="classpath:dbconfig.properties"/>
 <!-- 數據源 -->
 <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
  <property name="driverClass" value="${jdbc.driverClass}"></property>
  <property name="user" value="${jdbc.user}"></property>
  <property name="password" value="${jdbc.password}"></property>
 </bean>


 <!--掃描com.ssm所有的除了@Controller以外的其它注解,也就是service和dao層的注解
  service層注解 @Service dao層注解@Repository
 -->
 <context:component-scan base-package="com.ssm">
  <!-- 不能掃描控制器 -->
 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>


 <!-- 把mybatis和spring整合在一起,mybatis-config.xml也和applictionContext.xml同文件夾
   mapper/星號.xml 指定要掃描的映射文件(sql語句的xml文件)的路徑,和applictionContext.xml同文件夾 -->
 <!-- 配置和mybatis的整合 -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <!-- 指定mybatis 全局配置文件的位置 -->
  <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  <property name="dataSource" ref="pooledDataSource"></property>
  <!-- 指定mybatismapper文件的位置 -->
  <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
 </bean>



 <!-- 配置掃描器,將mybatis接口的實現加入到ioc容器中 -->
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <!-- 掃描所有的dao接口 -->
  <property name="basePackage" value="com.ssm.dao"></property>
 </bean>

 <!-- 事務控制的配置,為所有的非get開頭的service層方法織入事務 -->

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <!-- 控制數據源 -->
  <property name="dataSource" ref="pooledDataSource"></property>
 </bean>

 <aop:config>
  <!-- 切入點表達式 -->
  <aop:pointcut expression="execution(* com.liuzhan.service..*(..) )" id="txPoint"/>
  <!-- 配置事務 -->
  <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
 </aop:config>
 <!-- 配置事務增強 事務如何切入 -->
 <tx:advice id="txAdvice">

  <tx:attributes>
   <!-- 所有方法都是事務方法 -->
   <tx:method name="*"/>
   <!-- 以get開頭的所有方法 -->
   <tx:method name="get*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
</beans>

5.配置數據庫連接相關信息(dbconfig.properties)

ssm框架如何使用IDEA搭建

#數據庫連接
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm-crud&#63;useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#加載驅動
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#數據庫登錄用戶名
jdbc.user=root
#密碼
jdbc.password=root

6.mybatis配置文件(mybatis-config.xml)

ssm框架如何使用IDEA搭建

<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

</configuration>

注意:這里要建個mapper空文件,因為spring的配置文件applicationContext.xml
中有一項配置要掃描這個文件夾下的所有映射文件

ssm框架如何使用IDEA搭建

7.配置web.xml文件

web.xml
項目啟動,先加載web.xml文件的配置

ssm框架如何使用IDEA搭建

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
 <display-name>Archetype Created Web Application</display-name>

 <!-- 1.啟動spring容器,加載spring配置文件applicationContext.xml -->
 <!-- needed for ContextLoaderListener -->
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
 </context-param>

 <!-- Bootstraps the root web application context before servlet initialization -->
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>


 <!-- 2. 配置spring mvc 的前端控制器,DispatcherServlet類攔截所有請求,交給controller處理
 加載spring mvc配置文件(dispatcherServlet-servlrt.xml,還沒有建) -->
 <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
 <servlet>
 <servlet-name>dispatcherServlet</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <!-- 不寫,寫的話需要建個springmvc.xml就不需要dispatcherServlet-servlrt.xml -->
 <!-- <init-param>-->
 <!--  <param-name>contextConfigLocation</param-name>-->
 <!--  <param-value>classpath:springmvc.xml</param-value>-->
 <!-- </init-param>-->
 <load-on-startup>1</load-on-startup>
 </servlet>

 <!-- Map all requests to the DispatcherServlet for handling -->
 <servlet-mapping>
 <servlet-name>dispatcherServlet</servlet-name>
 <url-pattern>/</url-pattern>
 </servlet-mapping>



 <!-- 編碼過濾器,防止出現亂碼 -->
 <filter>
 <filter-name>characterEncodingFilter</filter-name>
 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
 <init-param>
  <param-name>encoding</param-name>
  <param-value>UTF-8</param-value>
 </init-param>
 </filter>

 <filter-mapping>
 <filter-name>characterEncodingFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

8.配置spring mvc配置文件(dispatcherServlet-servlet.xml)

spring mvc就是充當控制器,替代servlet

ssm框架如何使用IDEA搭建

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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.xsd">



 <!-- spring mvc主要作用就是充當控制器,只需要掃描controller -->
 <context:component-scan base-package="com.ssm" use-default-filters="false">
  <!-- 因為是spring mvc 只需要掃描控制器 -->
  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
 </context:component-scan>

 <!-- 配置視圖解析器 -->
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/views/"></property>
  <property name="suffix" value=".jsp"></property>
 </bean>

 <!-- 兩個標準配置 -->
 <!-- 將springmvc 不能處理的請求交給tomcat 例如靜態資源 -->
 <mvc:default-servlet-handler/>

 <mvc:annotation-driven>
  <mvc:message-converters>
   <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
   <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
  </mvc:message-converters>
 </mvc:annotation-driven>
</beans>

9.使用逆向工程前配置

ssm框架如何使用IDEA搭建

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

 <context id="DB2Tables" targetRuntime="MyBatis3">
  <!-- 配置數據連接信息 -->
  <jdbcConnection driverClass="com.mysql.jdbc.Driver"
      connectionURL="jdbc:mysql://localhost:3306/ssm-crud&#63;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=GMT%2B8"
      userId="root"
      password="root">
  </jdbcConnection>

  <javaTypeResolver >
   <property name="forceBigDecimals" value="false" />
  </javaTypeResolver>

  <!-- 指定java bean生成的位置 -->
  <javaModelGenerator targetPackage="com.ssm.entity" targetProject=".\src\main\java">
   <property name="enableSubPackages" value="true" />
   <property name="trimStrings" value="true" />
  </javaModelGenerator>

  <!-- 指定sql映射文件生成的位置 -->
  <sqlMapGenerator targetPackage="mapper"
       targetProject=".\src\main\resources">
   <property name="enableSubPackages" value="true" />
  </sqlMapGenerator>
  <!-- 指定dao接口生成的位置 -->
  <javaClientGenerator type="XMLMAPPER"
        targetPackage="com.ssm.dao"
        targetProject=".\src\main\java">
   <property name="enableSubPackages" value="true" />
  </javaClientGenerator>
  <!-- 指定每個表的生成策略,表和類對應關系 -->
  <table tableName="tbl_emp" domainObjectName="Employee"></table>
  <table tableName="tbl_dept" domainObjectName="Department"></table>
 </context>
</generatorConfiguration>

10.使用逆向工程生成接口、實體類、映射文件

ssm框架如何使用IDEA搭建

MBGTest.java

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MBGTest {
 public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
  List<String> warnings = new ArrayList<String>();
  boolean overwrite = true;
  File configFile = new File("mbg.xml");
  ConfigurationParser cp = new ConfigurationParser(warnings);
  Configuration config = cp.parseConfiguration(configFile);
  DefaultShellCallback callback = new DefaultShellCallback(overwrite);
  MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
  myBatisGenerator.generate(null);
 }
}

逆向工程生成

ssm框架如何使用IDEA搭建

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

保康县| 额济纳旗| 台安县| 贵州省| 武城县| 青川县| 望都县| 繁峙县| 巴林左旗| 当雄县| 张家港市| 塘沽区| 德兴市| 且末县| 项城市| 鲁甸县| 宁蒗| 临猗县| 邵武市| 资兴市| 容城县| 烟台市| 昭觉县| 大理市| 沙田区| 泸水县| 保山市| 梅州市| 恩平市| 遂平县| 太仆寺旗| 拜城县| 宜城市| 含山县| 门源| 安义县| 正镶白旗| 竹北市| 霍山县| 陇南市| 安吉县|