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 getUserName() {
        List 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 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 getOrders(@Param("date") int date,@Param("start") int start,@Param("pageNum") int pageNum);
    
    
}

maven配置文件如下



    4.0.0

    com.tcl.wechat
    demo
    0.0.1-SNAPSHOT
    jar

    demo
    Demo project for Spring Boot

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

    
        UTF-8
        UTF-8
        1.8
    

    
        
        org.springframework.boot
        spring-boot-starter
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
        org.mybatis.spring.boot
        mybatis-spring-boot-starter
        1.1.1
    
     
        mysql
        mysql-connector-java
    
     
        org.springframework.boot
        spring-boot-devtools
        true
    
    

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



你可能感兴趣的:(SpringBoot的第一应用)