ssm plug-in configuration (idea)

1.ssm框架springmvc-servlet配置
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
HTTP: // the WWW .springframework.org / Schema / tx / the Spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<! - scan global ->
<context: Component Base-Package-scan = "cn.kgc" />
! <- Mapper scan configuration ->
<the bean ID = "Configurer" class = "org.mybatis.spring. mapper.MapperScannerConfigurer ">
<Property name =" basePackage "value =" cn.kgc.mapper "/>
</ the bean>
<-! drive MVC annotation ->
<MVC: Annotation-Driven />
<-! annotation-driven transactions ->
<tx:annotation-driven/>
<!--驱动管理数据源-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/kgc"/>
<property name="username" value="root"/>
<property name="password" value="151506"/>
</bean>
<!--sqlSessionFactoryBean-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliases" value="cn.kgc.util.PageUtil"/>
<property name="typeAliasesPackage" value="cn.kgc.pojo"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>

<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=hsqldb
reasonable=true
</value>
</property>
</bean>
</array>
</property>

</bean>
<!--数据源事务管理-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<Property name = "the dataSource" REF = "the dataSource" />

</ the bean>


</ Beans>

2.mapper configure dynamic SQL statements:
<?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="cn.kgc.mapper.EmpMapper">
<select id="selectPage" parameterType="PageUtil" resultType="map">
SELECT d.dname,d.loc,e.* from emp e,dept d where e.deptno=d.deptno
<if test="emp!=null and emp.deptno!=null and emp.deptno!=-1">
and e.deptno=#{emp.deptno}
</if>
<if test="startrow!=null and pagesize!=null">
limit #{startrow},#{pagesize}
</if>
</select>
<select id="totalcount" parameterType="Emp" resultType="Integer">
SELECT count(*) from emp
<where>
<if test="deptno!=null and deptno!=-1">
AND deptno=#{deptno}
</if>
</where>
</select>
</mapper>

Guess you like

Origin www.cnblogs.com/hong999/p/11112119.html