SpringBoot的第一应用

今要开发一个数据同步接口,对外提供数据同步,打算用springboot快速开发试下。

@SpringBootApplication
@MapperScan("com.xxx.wechat.mapper")

@SpringBootApplication
@MapperScan("com.xxx.wechat.mapper")
public class DemoApplication {

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

API开发没有变化

@RestController
@EnableAutoConfiguration
@RequestMapping("/datacenter")
public class DataSyncToDataCenterApi {
    
    @Autowired
    private UserMapper userMapper;
    
    @Autowired
    private ProductCardStatMapper productCardStatMapper;

    @RequestMapping("getuser")
    public User getUser() {
        User user = new User();
        user.setName("test");
        return user;
    }
    
    @RequestMapping("getUserNames")
    public List<String> getUserName() {
        List<String> result = userMapper.getNickName();
        return result;
    }
package com.tcl.wechat.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.tcl.wechat.model.OrderStat;
import com.tcl.wechat.model.ProductStat;

public interface ProductCardStatMapper {

    @Select("SELECT p.product_name as productName,count(1) as productNum "
            + "FROM `product_card` pc, product p "
            + "WHERE pc.product_id = p.id and status=1 group by product_id limit #{start} ,#{pageNum}" )
    public List<ProductStat> getStock(int date,@Param("start") int start,@Param("pageNum") int pageNum);
    
    @Select("SELECT COUNT(1) from (SELECT p.product_name as productName,count(1) as productNum "
            + "FROM `product_card` pc, product p "
            + "WHERE pc.product_id = p.id and status=1 group by product_id) AS a_table")
    public int getProductCardRecordCount();
    
    @Select("SELECT COUNT(1) from `order` where DATE_FORMAT(update_time,'%Y%m%d')=#{date}")
    public int getOrderCount(int date);
    
    @Select("SELECT * from `order` where DATE_FORMAT(update_time,'%Y%m%d')=#{date} limit #{start} ,#{pageNum} ")
    @Results({
        @Result(id=true,property="id",column="id"),
        @Result(property="orderNo",column="order_no"),
        @Result(property="outTradeNo",column="out_trade_no"),
        @Result(property="payAmount",column="pay_amount"),
        @Result(property="orderType",column="order_type"),
        @Result(property="userId",column="user_id"),
        @Result(property="createTime",column="create_time"),
        @Result(property="createTime",column="create_time"),
        @Result(property="updateTime",column="update_time"),
        @Result(property="source",column="source"),
        @Result(property="businessType",column="business_type"),
        @Result(property="title",column="title"),
        @Result(property="goodsId",column="goods_id"),
        @Result(property="payTime",column="pay_time"),
        @Result(property="goodsId",column="goods_id"),
        @Result(property="productId",column="product_id")
    })
    public List<OrderStat> getOrders(@Param("date") int date,@Param("start") int start,@Param("pageNum") int pageNum);
    
    
}

maven配置文件如下

<?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.tcl.wechat</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.1.1</version>
    </dependency>
     <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,212评论 19 139
  • springboot 概述 SpringBoot能够快速开发,简化部署,适用于微服务 参考嘟嘟大神SpringBo...
    一纸砚白阅读 10,937评论 2 20
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,174评论 6 342
  • 2017年7月1日(连续第137天总结) 今日目标完成情况: 1:医院案例 100% 2:抄写概念5遍 100...
    我来学而时习之阅读 1,481评论 0 0
  • 不同于其他的时间管理,它教会我们把身体调整到最佳状态,从而高效率地完成每天最关键的任务。—《每天最重要的2个小时》...
    关键期育儿锦囊阅读 2,844评论 0 3

友情链接更多精彩内容