欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

LibrarySystem圖書管理系統(tǒng)(二)

 更新時(shí)間:2018年05月28日 08:33:34   作者:Remember_Ray  
這篇文章主要為大家詳細(xì)介紹了LibrarySystem圖書管理系統(tǒng)開發(fā)第二篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了LibrarySystem圖書管理系統(tǒng)第二篇,供大家參考,具體內(nèi)容如下

第一步:添加數(shù)據(jù)庫配置文件

jdbc.properties

# 數(shù)據(jù)庫驅(qū)動(dòng) 
jdbc.driver=com.mysql.jdbc.Driver 
 
# 數(shù)據(jù)庫地址 
jdbc.url=jdbc:mysql://localhost:3306/library?useUnicode=true&characterEncoding=UTF-8 
 
# 用戶名 
jdbc.username=root 
 
# 密碼 
jdbc.password=root 
 
# 初始化連接 
initialSize=0 
 
# 最大連接數(shù)量 
maxActive=20 
 
# 最大空閑連接 
maxIdle=20 
 
# 最小空閑連接 
minIdle=1 
 
# 超時(shí)等待時(shí)間 
maxWait=60000 

第二步:添加mybatis配置文件

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> 
<configuration> 
 <!-- 配置全局屬性 --> 
 <settings> 
  <!-- 使用jdbc的getGeneratedKeys獲取主鍵 --> 
  <setting name="useGeneratedKeys" value="true"/> 
 
  <!-- 使用別名替換列名, 默認(rèn)ture --> 
  <setting name="useColumnLabel" value="true"/> 
 
  <!-- 開啟駝峰命名轉(zhuǎn)換 --> 
  <setting name="mapUnderscoreToCamelCase" value="true"/> 
 </settings> 
</configuration> 

第三步:添加Spring配置文件

在resources/spring目錄下新建二個(gè)文件:

│   └── spring
│       ├── spring-mybatis.xml
│       ├── spring-service.xml
│       └── spring-mvc.xml

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:p="http://www.springframework.org/schema/p" 
  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-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/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 
 
 <!-- 注冊(cè)組件掃描器 --> 
 <context:component-scan base-package="com.ray.controller"/> 
 
 <!-- 訪問靜態(tài)資源 --> 
 <mvc:default-servlet-handler/> 
 
 <!-- 開啟注解模式 --> 
 <mvc:annotation-driven> 
  <mvc:message-converters> 
   <bean class="org.springframework.http.converter.StringHttpMessageConverter"> 
    <property name="supportedMediaTypes"> 
     <list> 
      <!-- 解決中文亂碼 --> 
      <value>text/plain;charset=UTF-8</value> 
      <value>text/html;charset=UTF-8</value> 
      <value>application/json;charset=UTF-8</value> 
     </list> 
    </property> 
   </bean> 
  </mvc:message-converters> 
 </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> 

spring-mybatis.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-3.1.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.1.xsd 
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx.xsd"> 
 
 <!-- 1.配置數(shù)據(jù)庫相關(guān)參數(shù) --> 
 <context:property-placeholder location="classpath:jdbc.properties"/> 
 
 <!-- 2.配置druid數(shù)據(jù)源 --> 
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 
  <!-- 配置連接池屬性 --> 
  <property name="driverClassName" value="${jdbc.driver}"/> 
  <property name="url" value="${jdbc.url}"/> 
  <property name="username" value="${jdbc.username}"/> 
  <property name="password" value="${jdbc.password}"/> 
 
  <!-- 配置初始化大小,最小,最大值 --> 
  <property name="initialSize" value="1"/> 
  <property name="minIdle" value="1"/> 
  <property name="maxActive" value="10"/> 
 
  <!-- 配置獲取連接等待超時(shí)的時(shí)間 --> 
  <property name="maxWait" value="10000"/> 
 
  <!-- 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉空閑連接,單位毫秒 --> 
  <property name="timeBetweenEvictionRunsMillis" value="60000"/> 
 
  <!-- 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒 --> 
  <property name="minEvictableIdleTimeMillis" value="300000"/> 
 
  <!-- 驗(yàn)證連接有效與否的SQL,不同的數(shù)據(jù)配置不同 --> 
  <property name="validationQuery" value="SELECT 1" /> 
 
  <!-- 如果空閑時(shí)間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測(cè)連接是否有效 --> 
  <property name="testWhileIdle" value="true"/> 
 
  <!-- 這里建議配置為TRUE,防止取到的連接不可用 --> 
  <property name="testOnBorrow" value="true"/> 
  <property name="testOnReturn" value="false"/> 
 
  <!-- 打開PSCache,并且指定每個(gè)連接上PSCache的大小 --> 
  <property name="poolPreparedStatements" value="true"/> 
  <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> 
 
  <!-- 這里配置提交方式,默認(rèn)就是TRUE,可以不用配置 --> 
  <property name="defaultAutoCommit" value="true" /> 
 
  <!-- 開啟Druid的監(jiān)控統(tǒng)計(jì)功能 --> 
  <property name="filters" value="stat"/> 
 </bean> 
 
 <!-- 3.配置Mybatis的SqlSessionFactory對(duì)象 --> 
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
  <!-- 配置MyBatis全局配置文件 --> 
  <property name="configLocation" value="classpath:mybatis-config.xml"/> 
  <!-- 注入數(shù)據(jù)庫連接池 --> 
  <property name="dataSource" ref="dataSource"/> 
  <!-- 掃描配置文件 --> 
  <property name="mapperLocations" value="classpath:mapping/*.xml"/> 
 </bean> 
 
 <!-- 4.配置掃描Dao接口包,動(dòng)態(tài)實(shí)現(xiàn)Dao接口,注入到spring容器中 --> 
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
  <!-- 給出需要掃描Dao接口包 --> 
  <property name="basePackage" value="com.ray.dao"/> 
 </bean> 
 
</beans> 

spring-service.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 
 http://www.springframework.org/schema/context/spring-context.xsd 
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx.xsd"> 
 
 <!-- 自動(dòng)掃描 --> 
 <context:component-scan base-package="com.ray"/> 
 
 <!-- 事務(wù)管理 --> 
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
  <property name="dataSource" ref="dataSource"/> 
 </bean> 
 
 <!-- 開啟事務(wù)控制的注解支持 --> 
 <tx:annotation-driven transaction-manager="transactionManager"/> 
</beans> 

 第四步:添加logback配置文件

logback配置比log4j要簡(jiǎn)單點(diǎn),功能類似

├── resources
│   ├── logback.xml

在resources文件夾下新建文件:logback.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<configuration debug="true"> 
 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
 <encoder> 
  <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
 </encoder> 
 </appender> 
 <!--開啟debug日志模式,在控制臺(tái)打印日志--> 
 <root level="debug"> 
 <appender-ref ref="STDOUT" /> 
 </root> 
</configuration>

第五步:配置web.xml

web.xml

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
   version="3.1" metadata-complete="true"> 
 <display-name>Archetype Created Web Application</display-name> 
 
 <!-- 配置DispatcherServlet --> 
 <servlet> 
 <servlet-name>seckill-dispatcher</servlet-name> 
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
 <!-- 配置springMVC需要加載的配置文件 
  spring-dao.xml,spring-service.xml,spring-web.xml 
  Mybatis - > spring -> springmvc 
  --> 
 <init-param> 
  <param-name>contextConfigLocation</param-name> 
  <param-value>classpath:spring/spring-*.xml</param-value> 
 </init-param> 
 <load-on-startup>1</load-on-startup> 
 <async-supported>true</async-supported> 
 </servlet> 
 <servlet-mapping> 
 <servlet-name>seckill-dispatcher</servlet-name> 
 <!-- 默認(rèn)匹配所有的請(qǐng)求 --> 
 <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> 
</web-app> 

項(xiàng)目結(jié)構(gòu):

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java內(nèi)存模型final的內(nèi)存語義

    Java內(nèi)存模型final的內(nèi)存語義

    這篇文章主要介紹了Java內(nèi)存模型final的內(nèi)存語義,上篇介紹volatile的內(nèi)存語義,本文講述的是final的內(nèi)存語義,相比之下,final域的讀和寫更像是普通變量的訪問。下面我們一起來看看文章學(xué)校內(nèi)容吧,需要的朋友可以參考一下
    2021-11-11
  • SpringBoot框架實(shí)現(xiàn)支付和轉(zhuǎn)賬功能

    SpringBoot框架實(shí)現(xiàn)支付和轉(zhuǎn)賬功能

    在 Spring Boot 框架中實(shí)現(xiàn)支付和轉(zhuǎn)賬功能時(shí),涉及到多個(gè)細(xì)節(jié)和注意點(diǎn),這些功能通常需要高度的安全性、穩(wěn)定性和可擴(kuò)展性,本文介紹了實(shí)現(xiàn)支付和轉(zhuǎn)賬功能的一些關(guān)鍵點(diǎn),需要的朋友可以參考下
    2024-08-08
  • Java中try-catch的使用及注意細(xì)節(jié)

    Java中try-catch的使用及注意細(xì)節(jié)

    現(xiàn)在有很多的語言都支持try-catch,比如常見的就是c++,java等,這篇文章主要給大家介紹了關(guān)于Java中try-catch的使用及注意細(xì)節(jié)的相關(guān)資料,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • Mybatis如何使用正則模糊匹配多個(gè)數(shù)據(jù)

    Mybatis如何使用正則模糊匹配多個(gè)數(shù)據(jù)

    這篇文章主要介紹了Mybatis如何使用正則模糊匹配多個(gè)數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • IDEA @SpringBootApplication報(bào)錯(cuò)原因及解決

    IDEA @SpringBootApplication報(bào)錯(cuò)原因及解決

    這篇文章主要介紹了IDEA @SpringBootApplication報(bào)錯(cuò)原因及解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Java枚舉學(xué)習(xí)之定義和基本特性詳解

    Java枚舉學(xué)習(xí)之定義和基本特性詳解

    枚舉是JAVA?5.0后增加的一個(gè)重要類型。可以用來表示一組取值范圍固定的變量。本文將通過示例為大家詳細(xì)講解枚舉的定義和基本特性,感興趣的可以了解一下
    2022-08-08
  • 區(qū)塊鏈常用數(shù)據(jù)庫leveldb用java來實(shí)現(xiàn)常規(guī)操作的方法

    區(qū)塊鏈常用數(shù)據(jù)庫leveldb用java來實(shí)現(xiàn)常規(guī)操作的方法

    這篇文章主要介紹了區(qū)塊鏈常用數(shù)據(jù)庫leveldb用java來實(shí)現(xiàn)常規(guī)操作,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-02-02
  • Java將Date日期類型字段轉(zhuǎn)換成json字符串的方法

    Java將Date日期類型字段轉(zhuǎn)換成json字符串的方法

    這篇文章主要給大家介紹了關(guān)于Java將Date日期類型字段轉(zhuǎn)換成json字符串的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • 基于SpringMVC的全局異常處理器介紹

    基于SpringMVC的全局異常處理器介紹

    下面小編就為大家?guī)硪黄赟pringMVC的全局異常處理器介紹。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • MyBatis-Plus將字段修改為空值的解決方案

    MyBatis-Plus將字段修改為空值的解決方案

    這篇文章主要介紹了MyBatis-Plus將字段修改為空值的解決方案,本文給大家分享三種常用的解決方案,感興趣的朋友一起看看吧
    2023-12-12

最新評(píng)論