springboot整合mybatis及封装curd操作-配置文件

1 配置文件  application.properties  #server server.port=8090 server.address=127.0.0.1 server.session.timeout=1800 server.error.whitelabel.enabled=true #mybatis mybatis.config-locations=classpath:mybatis/mybatis-config.xml // mybatis配置文件 mybatis.mapper-locations=classpath:mybatis/mapper/*.xml //mapper映射文件

 

mybatis-config.xml



"1.0" encoding="UTF-8" ?>
"-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

      
        
        
      "cacheEnabled" value="true"/>  
        
        "callSettersOnNulls" value="true"/>  
     
    
    
        "Integer" type="java.lang.Integer" />
        "Long" type="java.lang.Long" />
        "HashMap" type="java.util.HashMap" />
        "LinkedHashMap" type="java.util.LinkedHashMap" />
        "ArrayList" type="java.util.ArrayList" />
        "LinkedList" type="java.util.LinkedList" />
    
    
    
    
BaseMapper.xml





    
    
    
        insert into ${table}
        
            close=")" separator=",">
            ${item1}
        
        values
        
            close=")" separator=",">
            #{item2}
        
    
    
    
        useGeneratedKeys="true" keyProperty="id">
        insert into ${table}
        
            close=")" separator=",">
            ${item}
        
        values
        
            close=")" separator=",">
            #{item}
        
    

    
    
        update ${table} set
        
            separator=",">
            ${item} = #{columnvalues[${item}]}
        
        
            <if test="wheres != null">
                1=1
                
                    
                        
                            
                                
                                   
                                    ${item}
                                
                                <when
                                    test='val.toString() == "=" || val.toString() == "!=" || val.toString() == "<" || val.toString() == ">" 
                                      || val.toString() == "<=" || val.toString() == ">=" || val.toString() == "like" 
                                      || val.toString() == "is null" || val.toString() == "is not null"'>
                                     
                                
                                
                                    #{val}
                                
                            
                        
                    
                
            if>
        
    

    
    
        delete from ${table}
        
            <if test="wheres != null">
                1=1
                
                    
                        
                            
                                
                                   
                                    ${item}
                                
                                <when
                                    test='val.toString() == "=" || val.toString() == "!=" || val.toString() == "<" || val.toString() == ">" 
                                      || val.toString() == "<=" || val.toString() == ">=" || val.toString() == "like" 
                                      || val.toString() == "is null" || val.toString() == "is not null"'>
                                     
                                
                                
                                    #{val}
                                
                            
                        
                    
                
            if>
        
    

    
    
        delete from ${table}
        
            <if test="wheres != null">
                ${idkey} in
                
                    close=")" separator=",">
                    #{item}
                
            if>
        
    
    
    

    
    

    
    

    
    

    
    

    
    
         
    
    
    
         
    

    
    
         
    

    
    

    
    

    
    
pom.xml




    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

    com.example
    smalldemo
    2
    war

    SpringBootDemo
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.4.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.7
    

    
        
        
        
        
            org.springframework.boot
            spring-boot-starter-redis
            1.4.7.RELEASE
        

        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.0
        
        
            org.springframework.boot
            spring-boot-starter-web
            
        

        
            com.alibaba
            fastjson
            1.2.16
        
        
        
           com.alibaba
           druid-spring-boot-starter
           1.1.2
        
       
         
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
          
           com.caucho  
            hessian  
            4.0.38
        
        
        
        
        
        
                org.springframework.boot
                spring-boot-starter-tomcat
                provided
        
        
        
        
            com.github.wxpay
            wxpay-sdk
            0.0.3
        
        
            org.apache.httpcomponents
            httpclient
            4.5.3
        


        
            net.sourceforge.htmlunit
            htmlunit
        
    


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


Application.java

/**
 * 项目启动类
 * spring boot application只会扫描同一包下的类
 * @author sys
 *
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude = { JacksonAutoConfiguration.class })
@ServletComponentScan
@EnableTransactionManagement //加入事务注解
@MapperScan("com.sys.mapper")
public class Application  extends SpringBootServletInitializer{
        //fastkson
        @Bean
        public HttpMessageConverters fastJsonHttpMessageConverters() {
           FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
           FastJsonConfig fastJsonConfig = new FastJsonConfig();
           fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
           fastConverter.setFastJsonConfig(fastJsonConfig);
           HttpMessageConverter converter = fastConverter;
           return new HttpMessageConverters(converter);
        }
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
}

下篇继续--java对mybatis的curd封装 

要源码的联系 qq 2506715686

转载于:https://www.cnblogs.com/syscn/p/7506711.html

你可能感兴趣的:(springboot整合mybatis及封装curd操作-配置文件)