1

<?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.lin.ssm.mapper.BookMapper">

<resultMap id="BookResultMap" type="Book" />
 

<select id="findByTypeId"  parameterType="int" resultMap="BookResultMap">
    select * from tb_book where typeid=#{typeId}
</select>

</mapper>

<?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">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:app.xml</param-value>
</context-param>

<!-- spring 字符編碼過濾器 -->
<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>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<!-- 前端控制器  -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern><!-- 不能用/*  否則會覆蓋掉已有的配置 -->
</servlet-mapping>

<!-- spring mvc 容器的監(jiān)聽器 服務器已開啟,就開啟IOC容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

</web-app>

<?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:aop="http://www.springframework.org/schema/aop" 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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"
default-autowire="byType">

<!-- 尋找里面有service等四個注解 告訴他歸為容器管理 -->
<context:component-scan base-package="com.lin.ssm" />
<context:annotation-config />
<aop:aspectj-autoproxy /><!-- 自動通過aspectJ生成代理 -->

<!-- 連接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url"
        value="jdbc:mysql://localhost:3306/dang?useUincode=true&amp;characterEncoding=utf8" />
    <property name="username" value="root" />
    <property name="password" value="123456" />
    <!-- 還可以配置初始連接數(shù) 最大連接數(shù)等等 -->
</bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="com.lin.ssm.model" /><!-- 
        累的名字就是類型別名 -->
    <!-- <property name="typeHandlersPackage" value="com.lin.ssm.typehandlers" 
        /> -->
    <property name="mapperLocations" value="classpath*:com/lin/ssm/mapper/*.xml" /><!-- 
        映射器在哪里 -->
    <!-- <property name="configLocation" value="WEB-INF/mybatis-config.xml" 
        /> -->
</bean>

<!-- 通過他就找映射器 -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

</beans>

<?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" 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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"
default-autowire="byType">

<context:component-scan base-package="com.lin.ssm.controller" />
<context:annotation-config />
<!-- 處理靜態(tài)的資源 -->
<mvc:default-servlet-handler />
<!-- 靜態(tài)資源在哪里() 
<mvc:resources location="/WEB-INF/*" mapping="/resource" />-->

<!-- 配置MVC的試圖解析器 渲染視圖 完成模型和視圖的綁定 -->
<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>



 
 
 <!-- json消息轉(zhuǎn)換器 -->
 <mvc:annotation-driven>
       <mvc:message-converters>
         <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
         <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
         <bean class= "org.springframework.http.converter.StringHttpMessageConverter"/>
       </mvc:message-converters>
</mvc:annotation-driven>

</beans>

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容