Spring+hibernate+JSP实现Piano的数据库操作---4.配置文件
1.applicationContext.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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<description>Spring公共配置</description>
<!-- 配置Spring上下文的注解 -->
<context:annotation-config/>
<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
<context:component-scan base-package="com">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 属性文件位置 -->
<context:property-placeholder location="classpath:*.properties"/>
<!--数据源配置-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.entity"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.useUnicode">${hibernate.useUnicode}</prop>
<prop key="hibernate.characterEncoding">${hibernate.characterEncoding}</prop>
<prop key="current_session_context_class">thread</prop>
</props>
</property>
</bean>
<!-- 使用annotation定义事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>
2. spring-mvc.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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 自动扫描且只扫描@Controller -->
<context:component-scan base-package="com.controller">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:annotation-driven/>
<!-- 静态资源文件,不需要通过D****Servleet-->
<mvc:resources location="/static/" mapping="/static/**"/>
<!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
<!-- 定义JSP文件的位置 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
3.web.xml的配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>cakessh</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml
</param-value>
</context-param>
<!-- <listener>-->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>-->
<!-- </listener>-->
<!-- -->
<!-- <context-param>-->
<!-- <param-name>contextConfigLocation</param-name>-->
<!-- <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>-->
<!-- </context-param>-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</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>
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
一些关于数据库的配置 dbinfo.properties
#mysql
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/test2?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=
#hibernate
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.useUnicode=true
hibernate.characterEncoding=utf-8
Spring+hibernate+JSP实现Piano的数据库操作---4.配置文件的更多相关文章
- Spring+hibernate+JSP实现Piano的数据库操作---5.JSP页面
1.index.jsp <%-- Created by IntelliJ IDEA. User: lenovo Date: 2020/3/25 Time: 14:09 To change thi ...
- Spring+hibernate+JSP实现Piano的数据库操作---2.Controller+Service+Dao
Controller package com.controller; import com.entity.Piano; import org.dom4j.rule.Mode; import org.s ...
- Spring+hibernate+JSP实现Piano的数据库操作---3.Piano实体类
package com.entity; import org.springframework.stereotype.Component; import javax.persistence.*; @Co ...
- Spring+hibernate+JSP实现Piano的数据库操作---1.目录结构+展示
目录结构 界面
- jsp数据库连接大全和数据库操作封装到Javabean
一.jsp连接Oracle8/8i/9i数据库(用thin模式) testOracle.jsp如下: <%@ page contentType="text/html;charset=g ...
- jsp JDBC连接MySQL数据库操作标准流程参考
1. 此案例以帐号密码后台更新维护为例子,对数据库调取数据更新流程进行演示: 代码示例: <%@page import="java.io.IOException"%> ...
- spring+hibernate--直接修改数据库,再通过hibernate查询数据不变
这个问题已经很多天了,一直没有时间解决,不过还好是自己的项目,没什么影响. 刚好今天没事,想好好解决一下这个问题. hibernate主要配置如下: <property name="h ...
- 基于Spring和Mybatis拦截器实现数据库操作读写分离
首先需要配置好数据库的主从同步: 上一篇文章中有写到:https://www.cnblogs.com/xuyiqing/p/10647133.html 为什么要进行读写分离呢? 通常的Web应用大多数 ...
- spring boot快速入门 4: jpa数据库操作 实现增删改查
spring boot jpa逆向生成表 简单实例: 第一步:pom文件: <?xml version="1.0" encoding="UTF-8"?&g ...
随机推荐
- javaScript的三种储存方式
(一).SessionStorage 会话储存 (二).localStorage 本地储存 (三).Cookier 现实中为:饼干 ...
- 写出Python中列表、元祖、字典、字符串的至少5种以上的方法
1.列表 常用方法 作用 参数 append(data) 在尾部添加数据 data-加入到列表中的数据 insert(idx,data) 在指定位置添加数据 idx-索引 data-数据 ext ...
- Maven Jar包下载失败及解决方案
我是阿福,公众号「阿福聊编程」作者,一个在后端技术路上摸盘滚打的程序员,在进阶的路上,共勉! 文章已收录在 JavaSharing 中,包含Java技术文章,面试指南,资源分享. 明显的下载失败 具体 ...
- JS断点调试,必备的javaScript的debug调试技巧
1.断点调试是啥?难不难? 断点调试其实并不是多么复杂的一件事,简单的理解无外呼就是打开浏览器,打开sources找到js文件,在行号上点一下罢了.操作起来似乎很简单,其实很多人纠结的是,是在哪里打断 ...
- 洛谷CF1292A NEKO's Maze Game,还是思维。。。
题目直接找链接 题意: 有一个2*n大的平面,有的格子不能走,有的格子可以走,最初状态所有格子都可以走,有q个操作,每个操作都把某个格子变化一下:能走变不能走,不能走变能走,输出每次操作之后能否从1, ...
- Docker容器和镜像的区别
docker容器和镜像区别 转自 https://www.cnblogs.com/bethal/p/5942369.html 这篇文章希望能够帮助读者深入理解Docker的命令,还有容器(conta ...
- idea+DevTools热部署
1.增加devtools依赖 <!-- 热部署DevTools --> <dependency> <groupId>org.springframework.boot ...
- java 怎样 改变 数组元素的值
简介 (Introduction): 背景 需要解析Object数组中的数据,将数据(mintime)进行修改,改为(maxtime),修改后,生成新的对象 结构图 核心 对于Object数组的概念理 ...
- React中setState 什么时候是同步的,什么时候是异步的?
class Example extends React.Component { constructor() { super(); this.state = { val: 0 }; } componen ...
- vue中使用ts时如何导入mixins
方法一 // mixins.ts import { Vue } from "vue-property-decorator"; export class TableSelect ex ...