Springboot+Mybatis

pom配置

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sy</groupId>
  <artifactId>0415_SL</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>0415_SL Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>



  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
  </parent>

  <dependencies>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>


    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.4</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.2</version>
    </dependency>

    <!--redis-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>


    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.40</version>
    </dependency>

    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.12</version>
    </dependency>

    <!--JSTL-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!--JSP-->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

    <!--fastjson-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.56</version>
    </dependency>


  </dependencies>

  <build>
    <finalName>0415_SL</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <!--springBoot的maven插件-->
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>

    <!--指定打包的资源包-->
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.yml</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
    </resources>
  </build>
</project>

application.properties配置文件

#tomcat
server.port=8080
server.tomcat.uri-encoding=UTF-8
server.servlet.context-path=/

#指定使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

#dataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.1.197:3306/slsaledb
spring.datasource.username=root
spring.datasource.password=root

#springmvc
spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp
spring.mvc.static-path-pattern=/**
spring.mvc.servlet.path=/
spring.mvc.date-format=yyyy-MM-dd

#mybatisl;lk
mybatis.configuration.lazy-loading-enabled=false
mybatis.type-aliases-package=com.sy.model

#log4j
logging.level.org.springframework.web=DEBUG
logging.level.org.mybatis=debug
logging.level.com.sy=debug

#redis
spring.redis.host=localhost
spring.redis.database=0
spring.redis.port=6379

#post乱码解决
spring.http.encoding.charset=utf-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

# Single file max size
#multipart.maxFileSize=50Mb
## All files max size
#multipart.maxRequestSize=50Mb
#1.add 工作空间代码添加到index索引仓库
#2.commit把索引仓库中内容添加到本地仓库
#3.push把本地仓库中的代码推送到远程仓库

#如果多人修改同一个文件
#本地push--->merge(合并),即解决冲突--->[本地commit]--->push即可成功

#张三提交到远程仓库的代码


#李四提交的代码

config包

//SpringBootStarter启动类
package com.sy.config;

import org.springframework.boot.SpringApplication;

public class SpringBootStarter {

    public static void main(String[] args) {
        SpringApplication.run(SpringConfig.class,args);
    }
}

package com.sy.config;


import com.sy.interceptor.LoginInterceptor;
import com.sy.interceptor.SysConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication(scanBasePackages = {"com.sy"})
//生成mapper接口的实现类对像(动态代理产生的对像)
@MapperScan(basePackages = "com.sy.mapper")
//引入其他配置
@ImportAutoConfiguration(classes = SysConfig.class)
public class SpringConfig {

    @Bean(name = "loginInterceptor")
    public LoginInterceptor createSysInterceptor(){

        return new LoginInterceptor();
    }
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize("10240MB"); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("102400MB");
        return factory.createMultipartConfig();
    }


}

测试类

import com.sy.config.SpringConfig;
import com.sy.mapper.czx.UseraccountMapper;
import com.sy.model.czx.Useraccount;
import com.sy.service.czx.AfficheService;
import com.sy.service.czx.UseraccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SpringConfig.class)
public class tttt {
    @Autowired
    private UseraccountMapper useraccountMapper;
    @Autowired
    private UseraccountService service;
    @Autowired
    private AfficheService service2;
    @Test
    public void test1(){
//        Useraccount useraccount=new Useraccount();
//        useraccount.setUSER_ID(2);
//        useraccount.setBASE_BALANCE(8000);
//        useraccountMapper.insert(useraccount);
    }
    @Test
    public void test2(){
//        System.out.println(service.internalTransfer(1000.0,2,75));
    }
    @Test
    public void test3(){
        System.out.println(service2.findAll(0,5));
    }
}

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">
<mapper namespace="com.sy.mapper.czx.InformationMapper">
    <insert id="insert" parameterType="Information">
        INSERT INTO `slsaledb`.`information` ( `title`, `content`, `state`, `publisher`, `publishTime`, `typeId`, `typeName`, `fileName`, `filePath`, `fileSize`, `uploadTime`)
         VALUES ( #{title},#{content}, #{state}, #{publisher},now(), #{typeId}, #{typeName}, #{fileName}, #{filePath}, #{fileSize},now());
    </insert>
    <delete id="delete" parameterType="Information">
        DELETE from information WHERE id=#{id}
    </delete>
    <update id="update" parameterType="Information">
        UPDATE `slsaledb`.`information`
        <set>
            <if test="title!=null">
                `title`=#{title},
            </if>
            <if test="content!=null">
                `content`=#{content},
            </if>
            <if test="typeId!=null">
                `typeId`=#{typeId},
            </if>
            <if test="typeName!=null">
                `typeName`=#{typeName},
            </if>
            <if test="fileName!=null">
                `fileName`=#{fileName},
            </if>
            <if test="filePath!=null">
                `filePath`=#{filePath},
            </if>
            <if test="fileSize!=null">
                `fileSize`=#{fileSize},
            </if>
            <if test="state!=null">
                `state`=#{state},
            </if>
            `uploadTime`=now(),
        </set>
        WHERE (`id`=#{id});
    </update>
    <select id="select" resultType="Information">
        SELECT *FROM information
        <trim prefix="where" prefixOverrides="and|or">
            <if test="state!=null">
                and state=#{state}
            </if>
        </trim>
        ORDER BY publishTime DESC LIMIT #{page},#{pageSize}
    </select>
    <select id="selectCount" resultType="java.lang.Integer">
        SELECT count(*)FROM information
        <trim prefix="where" prefixOverrides="and|or">
            <if test="state!=null">
                and state=#{state}
            </if>
        </trim>
    </select>
    <select id="selectById" resultType="Information">
        SELECT *FROM information  WHERE (`id`=#{id});
    </select>
</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">
<mapper namespace="com.sy.mapper.czx.UseraccountMapper">
    <insert id="insert" parameterType="Useraccount">
        INSERT INTO `slsaledb`.`user_account_201404` ( `USER_ID`, `ACCOUNT_DATE`, `STAT`, `BASE_IN`, `BASE_OUT`, `BASE_BALANCE`, `REPEAT_IN`, `REPEAT_OUT`, `REPEAT_BALANCE`, `FREE_PV`, `ALREADY_PV`, `BUY_PV`,`NOTE`)
         VALUES (#{user_id}, now(), 1, #{base_in}, #{base_out}, #{base_balance}, #{repeat_in}, #{repeat_out}, #{repeat_balance}, #{free_pv}, #{already_pv}, #{buy_pv},#{note});
    </insert>
    <!--查找最新余额-->
    <select id="selectNewBalance" resultType="java.lang.Double">
        SELECT BASE_BALANCE from user_account_201404 WHERE USER_ID=#{user_id} ORDER BY ACCOUNT_DATE DESC LIMIT 1
    </select>
    <!--查找基本账户-->
    <select id="selectAll" resultType="Useraccount">
        select * FROM user_account_201404
        <trim prefix="where" prefixOverrides="and|or">
            BASE_BALANCE  !=0
            <if test="user_id!=null">
                and USER_ID=#{user_id}
            </if>
            <if test="beginTime!=null and endtime!=null">
                and ACCOUNT_DATE BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
        ORDER BY ACCOUNT_DATE DESC LIMIT #{page},#{pageSize}
    </select>
    <!--查询总数-->
    <select id="selectCount" resultType="java.lang.Long">
        select count(*) FROM user_account_201404
        <trim prefix="where" prefixOverrides="and|or">
            BASE_BALANCE  !=0
            <if test="user_id!=null">
                and USER_ID=#{user_id}
            </if>
            <if test="beginTime!=null and endtime!=null">
                and ACCOUNT_DATE BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
    </select>
    <!--查找重消账户-->
    <select id="selectAll2" resultType="Useraccount">
        select * FROM user_account_201404
        <trim prefix="where" prefixOverrides="and|or">
            REPEAT_BALANCE !=0
            <if test="user_id!=null">
                and USER_ID=#{user_id}
            </if>
            <if test="beginTime!=null and endtime!=null">
                and ACCOUNT_DATE BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
        ORDER BY ACCOUNT_DATE DESC LIMIT #{page},#{pageSize}
    </select>
    <!--查询总数-->
    <select id="selectCount2" resultType="java.lang.Long">
        select count(*) FROM user_account_201404
        <trim prefix="where" prefixOverrides="and|or">
            REPEAT_BALANCE  !=0
            <if test="user_id!=null">
                and USER_ID=#{user_id}
            </if>
            <if test="beginTime!=null and endtime!=null">
                and ACCOUNT_DATE BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
    </select>
    <select id="selectNewRBalance" resultType="java.lang.Double">
        SELECT REPEAT_BALANCE from user_account_201404 WHERE USER_ID=#{user_id} ORDER BY ACCOUNT_DATE DESC LIMIT 1
    </select>
</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">
<mapper namespace="com.sy.mapper.czx.UserCashMapper">
    <select id="select"  resultType="UserCash">
    select *from user_cash
        <trim prefix="where" prefixOverrides="and|or">
            USER_ID=#{user_id}
            <if test="beginTime!=null and endtime!=null">
                and CASH_TIME BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
     ORDER BY CASH_TIME DESC LIMIT #{page},#{pageSize}
    </select>
    <select id="selectCount"  resultType="java.lang.Integer">
        select count(*) from user_cash
        <trim prefix="where" prefixOverrides="and|or">
            USER_ID=#{user_id}
            <if test="beginTime!=null and endtime!=null">
                and CASH_TIME BETWEEN #{beginTime} and #{endtime}
            </if>
        </trim>
    </select>
    <insert id="insert" parameterType="Useraccount">
        INSERT INTO `slsaledb`.`user_cash` (`CASH_TIME`, `CASH_NUM`, `USER_ID`, `CASH_PV`, `CURRENCY`, `PV_RATE`, `CASH_MONEY`, `NOTE`, `FEE`, `TAX`, `OTHER_FEE`, `BANK_NAME`, `BANK_BRANCE`, `BANK_ACCOUNT`, `ACCOUNT_NAME`, `STAT`, `CREDITED_MONEY`, `CREDITED_TIME`, `OPERATOR`)
         VALUES ( now(), #{cash_num}, #{user_id}, #{cash_pv}, #{currency}, #{pv_rate}, #{cash_money}, #{note}, #{fee}, #{tax}, #{other_fee}, #{bank_name}, #{bank_brance}, #{bank_account}, #{account_name}, 1, #{credited_money}, #{credited_time}, #{operator});
    </insert>
</mapper>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值