SSM框架的常用配置信息

本文介绍了SSM(Spring、SpringMVC、Mybatis)框架中的常用配置文件,包括`application.properties`和`application.yml`,详细列出了数据库连接、Mybatis配置、静态资源路径等关键设置。同时,展示了Mybatis的Mapper XML文件示例,包括增删查改操作。此外,还提及了Spring MVC的`sprignmvc-servlet.xml`配置,用于处理Controller扫描和视图解析。这些配置对于理解和搭建SSM项目至关重要。

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

SSM框架中常用的配置文件

application.properties

#项目端口和项目名配置
server.port=8081
server.servlet.context-path=/ems

#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/my_learn?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456

#mybatis的文件配置
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.tian.pojo
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#静态资源的配置
spring.resources.static-locations=classpath:/templates/,classpath:/static/
spring.thymeleaf.cache=false

application.yml

#数据库配置,静态资源的配置
spring:
  datasource:
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/book?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC
  thymeleaf:
    cache: false
  resources:
    static-locations: classpath:/templates/,classpath:/static/

#mybatis的文件配置
mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.tian.pojo
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

#项目端口和项目名配置
server:
  port: 8888
  servlet:
    context-path: /tian

Mybatis配置信息

<?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.tian.dao.UserDao">

    <select id="listAll" resultType="User">
        select * from user
    </select>

    <select id="selectById" resultType="User">
        select * from user where id = #{id}
    </select>

    <insert id="add">
        insert into user value (#{id},#{username},#{password})
    </insert>

    <delete id="deleteById" parameterType="int">
        delete from user where id = #{id}
    </delete>

    <update id="update" parameterType="User">
        update user set username=#{username},password=#{password} where id=#{id}
    </update>
</mapper>

spring_xml配置.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="..." class="...">  
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <bean id="..." class="...">
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <!-- more bean definitions go here -->

</beans>

springmvc-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    <context:component-scan base-package="com.tian.controller" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>
</beans>

数据库通用配置信息

spring:
  datasource:
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/book?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC
  thymeleaf:
    cache: false


mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.tian.pojo
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

server:
  port: 8008

作者:SmartDragon

QQ邮箱:2455404279@qq.com

欢迎留言哈!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值