mvc:
throw-exception-if-no-handler-found: true
web:
resources:
add-mappings: false
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);
}
}
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);

最低0.47元/天 解锁文章
9571

被折叠的 条评论
为什么被折叠?



