ssm_webプロジェクトの作成と構成に関する注意事項

SSMフレームワーク

SSM(春、SpringMVC和Mybatis)

  1. Spring
    Springは、制御の反転(IoC)およびアスペクト指向(AOP)コンテナーフレームワークの軽量化です。
    当初の意図
    1.JAVAEEの開発はより単純でなければなりません。
    2.クラスの代わりにインターフェースを使用することをお勧めします。Springは、インターフェースの使用の複雑さをほぼゼロに減らします。
    3.JavaBean用のより優れたアプリケーション構成フレームワークを提供します。
    4. JAVA EEなどの現在のテクノロジーではなく、オブジェクト指向設計に重点を置きます。
    5.不要な例外キャプチャを最小限に抑えます。
    6.アプリケーションのテストを容易にします。
    Springの目標:
    1。Springを使用するのは便利で快適です。
    2.アプリケーションコードはSpringAPIに依存しません。
    3. Springは既存のソリューションと競合しませんが、それらの統合に取り組んでいます。
    Springの目標:
    1。Springを使用するのは便利で快適です。
    2.アプリケーションコードはSpringAPIに依存しません。
    3. Springは既存のソリューションと競合しませんが、それらの統合に取り組んでいます。
  2. SpringMvc
    SpringmvcはSpringフレームワークのモジュールであり、springとspringmvcを中間統合レイヤーと統合する必要はありません。Springmvcは、mvcに基づくWebフレームワークです。Spring
    フレームワークは、Webアプリケーションを構築するためのフル機能のMVCモジュールを提供します。Springプラグ可能MVCアーキテクチャーを使用して、Web開発にSpringを使用する場合、SpringのSpring MVCフレームワークを使用するか、他のMVC開発フレームワークを統合するかを選択できます。
  3. MyBatis
    MyBatisはApacheのオープンソースプロジェクトiBatisであり、MyBatisは、カスタムSQL、ストアドプロシージャ、および高度なマッピングをサポートする優れた永続性レイヤーフレームワークです。MyBatisは、ほとんどすべてのJDBCコードと、パラメーターの設定および結果セットの取得の作業を排除します。MyBatisは、プリミティブ型、インターフェイス、およびJava POJO(Plain Old Java Objects)を、単純なXMLまたはアノテーションを介してデータベース内のレコードとして構成およびマップできます。

SSMフレームワークに基づいてWebプロジェクトを作成する

  1. プロジェクトを作成する
    ここに画像の説明を挿入
  2. 関連するjarパッケージをpomファイルにインポートします
    ここに画像の説明を挿入
    ここに画像の説明を挿入
  3. ジェネレーターに従ってdaoファイルとエンティティーファイルを作成します。
    ここに画像の説明を挿入
    ここに画像の説明を挿入
    ファイルとコードを生成します。generator.xmlファイル
    ここに画像の説明を挿入
    は、チュートリアルシーケンスの公式Webサイトで入手できます。
    ここに画像の説明を挿入
  4. 構成ファイル
    ここに画像の説明を挿入
    application.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: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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!--包扫描-->
    <context:component-scan base-package="com.liu.service"/>
    <!--引入数据源的属性文件-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!--数据源配置-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="driverClassName" value="${jdbc.driverName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="initialSize" value="5"/>
        <property name="maxActive" value="20"/>
    </bean>
    <!--sessionFactory-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        <!--PageHelper分页插件-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>
                            params=value1
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <!--为dao生成实现类型-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.liu.dao"/>
    </bean>
    <!--事务类-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
   <!--开启事务驱动-->
   <!--此处注意导包不要导错,结尾为tx的包为正确的包
   xmlns:tx="http://www.springframework.org/schema/tx"
   -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

springmvc.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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--包扫描-->
    <context:component-scan base-package="com.liu.controller"/>
    <!--静态资源放行-->
    <mvc:default-servlet-handler/>
    <!--开启驱动注解-->
    <mvc:annotation-driven/>
    <!--视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

db.properties構成ファイル

jdbc.username=root
jdbc.password=密码
jdbc.driverName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3308/ssm_crud?characterEncoding=utf8&useSSL=false

他の文書は自分で書いています

おすすめ

転載: blog.csdn.net/GUANGZHES/article/details/115261873
おすすめ