SSM项目的各种配置

本文详细介绍了SSM项目(Spring、SpringMVC、Mybatis)的配置步骤,包括项目的结构目录、mapper XML文件配置、spring的applicationContext.xml配置、springMVC的dispatcherServlet.xml配置、jdbc.properties配置、mybatis.xml配置、web.xml配置以及pom.xml配置,重点关注了各配置文件中的关键修改部分,如数据库连接、Mapper接口和实体类配置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、项目的结构目录

此处注意的是资源文件夹在conf的下面
在这里插入图片描述

二、mapper的xml文件配置

修改的部分

  1. 壹:改为Dao接口的全限定名称
  2. 贰:改为Dao接口中对应的方法的名称
  3. 叁:改为实体类对应的全限定名称,即查询操作后返回的类型(要求所有属性都要是有set方法,应为是要靠set注入传递值的)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="--------壹-----com.bjpowernode.dao.StudentDao">
    <select id="selectStudents--------贰--------" resultType="com.bjpowernode.damain.Student--------叁---------">
           select id,name,age from student;
    </select>
    <insert id="insertStudent">
         insert into student(name,age) values(#{name},#{age})
    </insert>
</mapper>

三、spring的配置文件----applicationContext.xml

修改的位置

  1. 壹:连接数据库所需要的配置文件的地址
  2. 贰:加载mybatis中的配置文件
  3. 叁:加载所有的一个包下的mapper.xml文件
  4. 肆:加载一个包下的所有的带有@Service文件
<?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:util="http://www.springframework.org/schema/util"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util
       https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!--
          用于声明配置文件的位置,一使得下面的属性可以连接到有关于数据库的配置信息
          -->
    <context:property-placeholder location="--------壹-----classpath:conf/jdbc.properties"/>
    <!--<util:property-path path="classpath:jdbc.properties"/>-->
    <!--声明数据源Datasource,作用是连接数据库的-->
    <bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <!--使用set注入给DruidDataSource赋值-->
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <!--表示最大的连接数量-->
        <property name="maxActive" value="${jdbc.maxHuman}"/>
    </bean>
    <!--声明的是mybatis中提供的的sqlSessionFactory类,这个类中创建sqlSession的-->
    <bean id="SqlSessionFactory"
          class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--set注入,将阿里数据库的连接池赋值给dataSource-->
        <property name="dataSource" ref="myDataSource"/>
        <!--
            mybatis中主配置文件的位置,用于读取主配置文件
            -->
        <property name="configLocation" value="--------贰-----classpath:conf/mybatis.xml"/>
    </bean>

    <bean
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值