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
欢迎留言哈!