spring,springmvc,mybatis框架总合

如何使用ssm

  1. maven导入相关依赖依赖
 <properties>
        <spring.version>5.0.2.RELEASE</spring.version>
        <slf4j.version>1.6.6</slf4j.version>
        <log4j.version>1.2.12</log4j.version>
        <oracle.version>11.2.0.1.0</oracle.version>
        <mybatis.version>3.4.5</mybatis.version>
        <spring.security.version>5.0.1.RELEASE</spring.security.version>
    </properties>

    <dependencies>        <!-- spring -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.8</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>        <!-- log start -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>        <!-- log end -->
        
         <!--mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        
        <!--spring的mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency>
        <!--spring mvc -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.security.version}</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>${oracle.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>jsr250-api</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.2</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
  1. 配置相关xxx.xml 文件(注意我这里的是ssm额配置)
    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: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/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
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 开启注解扫描,管理service和dao -->
    <context:component-scan base-package="com.itheima.ssm.service">
    </context:component-scan>
    <context:component-scan base-package="com.itheima.ssm.dao">
    </context:component-scan>

    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!-- 把交给IOC管理 SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 传入PageHelper的插件 -->
        <property name="plugins">
            <array>
                <!-- 传入插件的对象 -->
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">oracle</prop>
                            <prop key="reasonable">true</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <!-- 扫描dao接口 -->
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.itheima.ssm.dao"/>
    </bean>

    <!-- 配置Spring的声明式事务管理 -->
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

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

</beans>

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.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
           ">

    <!-- 扫描controller的注解,别的不扫描 -->
    <context:component-scan base-package="com.itheima.ssm.controller">
    </context:component-scan>

    <!-- 配置视图解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- JSP文件所在的目录 -->
        <property name="prefix" value="/pages/" />
        <!-- 文件的后缀名 -->
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- 设置静态资源不过滤 -->
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/img/" mapping="/img/**" />
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:resources location="/plugins/" mapping="/plugins/**" />

    <!-- 开启对SpringMVC注解的支持 -->
    <mvc:annotation-driven />

    <!--
        支持AOP的注解支持,AOP底层使用代理技术
        JDK动态代理,要求必须有接口
        cglib代理,生成子类对象,proxy-target-class="true" 默认使用cglib的方式
    -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

</beans>

spring-security.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:security="http://www.springframework.org/schema/security"
       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.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd">

    <security:global-method-security pre-post-annotations="enabled" jsr250-annotations="enabled" secured-annotations="enabled"></security:global-method-security>

    <!-- 配置不拦截的资源 -->
    <security:http pattern="/login.jsp" security="none"/>
    <security:http pattern="/failer.jsp" security="none"/>
    <security:http pattern="/css/**" security="none"/>
    <security:http pattern="/img/**" security="none"/>
    <security:http pattern="/plugins/**" security="none"/>
    <!--
    	配置具体的规则
    	auto-config="true"	不用自己编写登录的页面,框架提供默认登录页面
    	use-expressions="false"	是否使用SPEL表达式(没学习过)
    -->
    <security:http auto-config="true" use-expressions="true">
        <!-- 配置具体的拦截的规则 pattern="请求路径的规则" access="访问系统的人,必须有ROLE_USER的角色" -->
        <security:intercept-url pattern="/**" access="hasAnyRole('ROLE_USER','ROLE_ADMIN')"/>

        <!-- 定义跳转的具体的页面 -->
        <security:form-login
                login-page="/login.jsp"
                login-processing-url="/login.do"
                default-target-url="/index.jsp"
                authentication-failure-url="/failer.jsp"
                authentication-success-forward-url="/pages/main.jsp"
        />

        <!-- 关闭跨域请求 -->
        <security:csrf disabled="true"/>
        <!-- 退出 -->
        <security:logout invalidate-session="true" logout-url="/logout.do" logout-success-url="/login.jsp"/>

    </security:http>

    <!-- 切换成数据库中的用户名和密码 -->
    <security:authentication-manager>
        <security:authentication-provider user-service-ref="userService">
            <!-- 配置加密的方式-->
            <security:password-encoder ref="passwordEncoder"/>
        </security:authentication-provider>
    </security:authentication-manager>
    <!-- 配置加密类 -->
        <bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
   <!-- <bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />-->
    <!-- 提供了入门的方式,在内存中存入用户名和密码
    <security:authentication-manager>
    	<security:authentication-provider>
    		<security:user-service>
    			<security:user name="admin" password="{noop}admin" authorities="ROLE_USER"/>
    		</security:user-service>
    	</security:authentication-provider>
    </security:authentication-manager>
    --></beans>

db.properties
在这里插入图片描述
注意还有web文件

<?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"
         version="3.1">

    <!-- 配置加载类路径的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml,classpath*:spring-security.xml</param-value>
    </context-param>

    <!-- 配置监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
   <listener>
       <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
   </listener>

    <!-- 解决中文乱码过滤器 -->
    <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>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- 前端控制器(加载classpath:springmvc.xml 服务器启动创建servlet) -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 配置初始化参数,创建完DispatcherServlet对象,加载springmvc.xml配置文件 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <!-- 服务器启动的时候,让DispatcherServlet对象创建 -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>


    <error-page>
        <error-code>403</error-code>
        <location>/403.jsp</location>
    </error-page>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

一丶spring介绍

spring:spring可以看做是项目的管家,负责管理项目中的所有对象(包括web层,service层和dao层)。还可以看作容器 融合其他框架的

  1. IOC(控制反转):传统的项目工程需要我们自己的new对象,自己调取对象的方法和属性 而使用spring就不用,它回事用工工厂模式自动帮我创建!
  2. DI(依赖注入):spring 使用javaBean对象的set方法或者带参数的构造方法为我们在创建对象时自动设置所需要的属性值
  3. Aop(面向切面编程):在面向对象编程(oop)思想中,我们将事物抽成一个个对象,而在aop中我们将对象莫些类似的的方面抽成一个切面,对这个切面进行一些权限,事物,日志等处理。aop底层是动态代理哦!
    我的理解更像是做小手术 切开小口子让项目的莫些功能得到增强 !

spring常用注解:
这里需要注意的是注解是需要在xml文件中配置后才能使用哦!


#(@Bean)注解表明该方法会返回一个对象,并需要将其注册为Spring应用上下文中的bean,并且可以在方法中完成依赖注入;

(@Configuration)注解表明此类为配置类,包含了Spring应用上下文中如何创建bean的细节;

(@Component)注解表明该类会作为组件类,并告知Spring要为此类创建bean;

(@ComponentScan(packName))注解表明在指定包下扫描带有Component注解的类,并为其创建bean;

#(@AutoWired)注解申明了依赖,自动装配,可以用于属性和set方法;

#(@Import(xxx.class))注解将括号中声明的JAVA配置类导入当前配置类;

#(@ImportResource(classpath:xxx.xml))注解将括号中声明的XML配置导入当前配置类;

#(@Profile())注解表明只有此Profile激活时(配置spring.profile.active和spring.profile.default),此Bean才会被创建,没有Profile注解的总是会被创建;

#(@Conditional(? implents Condition))注解表明只有给定条件计算结果为true时才会创建bean,可以用于带@Bean注解的方法上,括号内为实现了

Condition接口的类;

#(@Primary)当匹配的Bean不止一个时,此注解可以设置首选,避免自动装配时的歧义性;

(@Qualifier)注解使用限定符,在可选Bean上缩小范围最终达到只有1个Bean满足所规定的限制条件;

#(@Scope)注解声明了bean的作用域;proxyMode属性设置作用域代理,代理对bean进行懒解释并将调用委托给会话/请求作用域内真正的bean;

(@Aspect)注解表明该类是一个切面;

   -(@Pointcut)注解表明在一个@Aspect切面内定义可重用的切点
   
   -(@After)注解表明通知方法会在目标方法返回或抛出异常后调用;
   
   -(@AfterReturning)注解表明通知方法会在目标方法返回后调用;
   
   -(@AfterThrowing)注解表明通知方法会在目标方法抛出异常后调用;
   
   -(@Around)注解表明通知方法会将目标方法封装起来;该通知方法需要接受ProceedingJoinPoint作为参数,通过它来调用被通知的方法,当要将控制权交给被通知方法时,需要调用它的proceed方法;
   
   -(@Before)注解表明通知方法会在目标方法调用之前执行;
   
   -(@DeclareParents)注解表明将接口引入到bean中;所标注的静态属性指明了要引入的接口;
   
      -(value)属性指定了哪种类型的bean要引入该接口,+号表示该类的所有子类且不包含该类自身;
      
      -(defaultImpl)属性指定了为引入功能提供实现的类;
      
(@EnableAspectJ-AutoProxy)注解表明可以在配置类

@Configuration的类级别上使用此注解启动自动代理功能,自动代理会为使用

@Aspect注解的bean创建一个代理,此代理会围绕该切面的切点所匹配的bean;

(@EnableWebMvc)启用Spring MVC(@Controller)声明一个控制器,基于@Componet注解,辅助实现组件扫描;
  
   -(@RequetsMapping)注解声明了它们所要处理的请求,可以在类和方法上声明;
       -(value)指定了该方法索要处理的请求路径;
       -(method)属性细化了它所处理的HTTP方法(get, post);
       (@RequestParam) 
       (@PathVariable)



spring注解详解

二丶spring mvc介绍

springmvc:springmvc是spring框架的一个模块,springmvc和spring无需通过中间整合层进行整合。springmvc是一个基于mvc的web框架。

spring详解参考文献:

springmvc常用注解
springmvc常用注解详解

三丶mybatis介绍

mybatis:是一个持久型数据连接框架,它内部集齐连接池和缓存机制,可减少不必要的资源浪费,反应更快捷

、Mybatis中的缓存
什么是缓存
存在于内存中的临时数据。
为什么使用缓存
减少和数据库的交互次数,提高执行效率。
什么样的数据能使用缓存,什么样的数据不能使用
适用于缓存:
经常查询并且不经常改变的。
数据的正确与否对最终结果影响不大的。
不适用于缓存:
经常改变的数据
数据的正确与否对最终结果影响很大的。
例如:商品的库存,银行的汇率,股市的牌价。
Mybatis中的一级缓存和二级缓存
一级缓存:
它指的是Mybatis中SqlSession对象的缓存。
当我们执行查询之后,查询的结果会同时存入到SqlSession为我们提供一块区域中。
该区域的结构是一个Map。当我们再次查询同样的数据,mybatis会先去sqlsession中
查询是否有,有的话直接拿出来用。
当SqlSession对象消失时,mybatis的一级缓存也就消失了。
二级缓存:
它指的是Mybatis中SqlSessionFactory对象的缓存。由同一个SqlSessionFactory对象创建的SqlSession共享其缓存。
二级缓存的使用步骤:
第一步:让Mybatis框架支持二级缓存(在SqlMapConfig.xml中配置)
第二步:让当前的映射文件支持二级缓存(在IUserDao.xml中配置)
第三步:让当前的操作支持二级缓存(在select标签中配置)
3、Mybatis中的注解开发
环境搭建
单表CRUD操作(代理Dao方式)
多表查询操作
缓存的配置

在这里插入图片描述

以下是mapper 映射的配置文件 可以配合注解使用更为方便

<?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">
<!-- dao层 里面存放各种操作 -->
<!-- namespace指定dao接口的全限定名 -->
<mapper namespace="mappers.UserMapper">
  <!--  id 放接口中的方法名
     resultType:结果集的类型,用在全自动映射中-->
   <select id="findAll" resultType="User">
       select * from smbms_user
   </select>
    <select id="findUserById" parameterType="int" resultType="User">
       select * from smbms_user where id =#{id}
   </select>
    <select id="findUserByNameAndPassword"  resultType="User">
       select * from smbms_user where userCode =#{username} and userPassword = #{password}
   </select>
    <select id="findUserByIdAndPhone" parameterType="user" resultType="User">
       select * from smbms_user where id =#{id} and phone = #{phone}
   </select>

    <select id="findCountUser"  resultType="int">
       select count(*) from smbms_user
   </select>

    <update id=" updateUserById" parameterType="User">
      update smbms_user set userPassword =#{userPassword} , Phone=#{phone} where Id = #{id}
   </update>

  <!--&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;-->
   <resultMap id="getName" type="User">
       <result property="id" column="id"/>
       <result property="userCode" column="userCode"/>   <!--property : 对应对象属性  column:对象查询出字段名(数据库字段)-->
       <result property="userName" column="userName"/>
       <result property="userRole" column="userRole"/>
       <result property="roleName" column="roleName"/>
   </resultMap>

    <select id="finAllByUserNameAndUserRold" resultMap="getName">
        select u.* ,r.roleName from smbms_user u,smbms_role r where u.userRole =r.id and u.userName like concat('%',#{userName},'%') and u.userRole=#{userRole}
    </select>

    <resultMap id="gerRold" type="User">

        <id property="id" column="id"></id>
        <result property="userCode" column="userCode"/>
        <result property="userName" column="userName"/>
        <result property="roleName"  column="roleName"/>
        <association property="role" javaType="Role">             <!--javaType-->
            <result property="id" column="r_id"/>
            <result property="roleCode" column="roleCode"/>
            <result property="roleName" column="roleName"/>
        </association>
    </resultMap>

    <resultMap id="getAddress" type="User">
        <id property="id" column="id" />
        <result property="userCode" column="userCode"/>
        <result property="userName" column="userName"/>
        <result property="userRole" column="userRole"/>
        <collection property="addresses" ofType="Address">
            <id property="id" column="a_id"/>
            <result property="contact" column="contact"/>
            <result property="addressDesc" column="addressDesc"/>

        </collection>
    </resultMap>

    <select id="findUsersByUserRole" resultMap="gerRold">
        select u.*,r.id r_id,r.roleName,r.roleCode  from smbms_user u ,smbms_role r
            where u.userRole = r.id
                and  u.userRole= #{userRole}
    </select>

    <select id="getAddressListByUserid" resultMap="getAddress">
            select u.*,a.addressDesc, a.contact,a.id a_id from smbms_user u,smbms_address a  where u.id=a.userid and u.id=#{id}
    </select>
   <!-- &#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;-->
    <!--作业-->
    <select resultType="int" id="findProviderRecord">select count(*) from smbms_provider </select>

    <select resultType="Provider" id="findProviderByName" parameterType="String">select * from smbms_provider where proContact like concat('%',#{name},'%') </select>

    <select resultType="Provider" id="findProviderById" parameterType="int">select * from smbms_provider where id = #{id}; </select>

    <update id="updateProviderById" parameterType="Provider">update smbms_provider set proName = #{proName},proDesc = #{proDesc},proContact = #{proContact} where id = #{id} </update>

    <resultMap id="getP" type="Provider">
        <id property="id" column="id"/>
        <result property="proCode" column="proName"/>
        <result property="proName" column="proName"/>
        <result property="proContact" column="proContact"/>
        <result property="proPhone" column="proPhone"/>
        <collection property="billList" ofType="Bill">
            <id property="" column=""/>
            <result property="" column=""/>
            <result property="" column=""/>
            <result property="" column=""/>

        </collection>
    </resultMap>

    <select id="getProviderById" resultMap="getP">
        select  from smbms_provider p smbms_bill b where p.id = b.providerid and p.id = #{id}
    </select>


    <select id="getProviderById" resultMap="getP">
        select  from smbms_provider p smbms_bill b where p.id = b.providerid and p.id = #{id}
    </select>
</mapper>

mybatis中文文档介绍

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

废弃的root

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值