SpringBoot+MyBatisPlus+Vue 前后端分离项目快速搭建【后端篇】【快速生成后端代码

mvc:

throw-exception-if-no-handler-found: true

web:

resources:

add-mappings: false

6、在启动类上添加@MapperScan


SpringbootServerApplication:

package com.keafmd;

import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

@MapperScan(“com.keafmd.mapper”)

public class SpringbootServerApplication {

public static void main(String[] args) {

SpringApplication.run(SpringbootServerApplication.class, args);

}

}

7、编写测试代码测试数据库是否连接正确


1、在 UserMapper代码页大括号内,按下Alt+Insert,选择Test

在这里插入图片描述

2、Ok

在这里插入图片描述

3、自动生成了测试类

在这里插入图片描述

4、编写测试代码

UserMapperTest :

package com.keafmd.mapper;

import com.keafmd.SpringbootServerApplication;

import com.keafmd.entity.User;

import com.keafmd.service.UserService;

import org.junit.jupiter.api.Test;

import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = SpringbootServerApplication.class)

class UserMapperTest {

@Resource

UserService userService;

@Test

public void test1(){

List userList = userService.list();

for (User user : userList) {

System.out.println(user);

}

}

}

5、测试结果

在这里插入图片描述

至此,后端和数据库连接没问题。

8、编写后端的工具类代码(封装结果集、日期处理、解决跨域请求)


在这里插入图片描述

1、CommonResult

package com.keafmd.common;

import lombok.Getter;

/**

  • Keafmd

  • @ClassName: CommonResult

  • @Description: 封装结果集

  • @author: 牛哄哄的柯南

  • @Date: 2021-04-29 18:11

  • @Blog: https://keafmd.blog.youkuaiyun.com/

*/

@Getter

public class CommonResult {

private Integer code;

private String message;

private Object obj;

private CommonResult(Integer code, String message, Object obj) {

this.code = code;

this.message = message;

this.obj = obj;

}

public static CommonResult nohandler() {

return new CommonResult(ResultCode.NOHANDLER.getCode(), ResultCode.NOHANDLER.getMessage(),null);

}

public static CommonResult success(Object data) {

return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),data);

}

public static CommonResult failed() {

return new CommonResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(),null);

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值