springboot

springboot集成mybatis

2020-07-01  本文已影响0人  Geroge1226

1、介绍

首先建立一个springboot web项目,在此基础上集成mybatis

2、使用

     <!--mybatis引用-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>

        <!-- jdbc引用 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
@Api(value = "健身助手服务")
@RequestMapping("/api/fitness")
@RestController
public class FitnessHelperController extends BaseController {


    @Autowired
    private FitnessHelperService service;

    /**
     * @name: signIn
     * @description: 签到送券码
     * @return: com.service.common.UniformResultTemplate<java.lang.Integer>
     * @date: 2020-06-28 10:51
     * @auther: xxx
     *
    */
    @ApiOperation(value = "2499会员卡签到")
    @RequestMapping(value = "/signin",method = RequestMethod.POST)
    public UniformResultTemplate<Integer> signIn(@RequestBody @Valid FitnessSigninReqVO reqVO, BindingResult result){
        if(result.hasErrors()){
           return super.fail(result.getFieldError().getDefaultMessage());
        }
        return success(service.addFitnessSignData(reqVO));
    }
public interface FitnessHelperService {
    Integer addFitnessSignData(FitnessSigninReqVO vo);
}
@Service
@Slf4j
public class FitnessHelperServiceImpl implements FitnessHelperService {

    @Autowired
    private SportFintessSignTotalMapper totalMapper;

    @Autowired
    private SportFitnessSignLogMapper logMapper;

    @Autowired
    private EsbTerminalFeign esbTerminalFeign;

    private String couponId="1234";

    // 新增签到数据
    @Override
    public Integer addFitnessSignData(FitnessSigninReqVO vo) {
        // 1、新增数据记录
        SportFitnessSignLog record = new SportFitnessSignLog();
        BeanUtils.copyProperties(vo,record);
        int a = logMapper.insertSelective(record);
        if(a <= 0){
            throw new CustomException(Code.FAIL.getCode(),"新增失败");
        }
        // 2、赠券
        CouponSendReqDTO dto = new CouponSendReqDTO();
        dto.setMemberId(Long.parseLong(vo.getMemberId()));
        dto.setCouponId(Long.parseLong(couponId));
        esbTerminalFeign.sendCoupon(dto);
        return record.getId();
    }
}
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/pousheng_source?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
    username: root
    password: lsy641
mybatis:
    mapper-locations: classpath*:mappers/*.xml

以上不指定扫码文件会报:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pousheng.fitnesshelper.dao.SportFitnessSignLogMapper.insertSelective
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
    at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:107)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    at com.sun.proxy.$Proxy94.insertSelective(Unknown Source)
    at com.pousheng.fitnesshelper.service.impl.FitnessHelperServiceImpl.addFitnessSignData(FitnessHelperServiceImpl.java:52)
    at com.pousheng.fitnesshelper.controller.FitnessHelperController.signIn(FitnessHelperController.java:53)

原因:springboot项目启动扫码文件

上一篇 下一篇

猜你喜欢

热点阅读