pom.xnl引入依赖
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.0</version> </dependency>
1、先建个表
2、 代码
2.1 创建User类
@Data
@NoArgsConstructor
@AllArgsConstructor // lombok插件
public class User {
private Integer id;
private String username;
private String password;
private String nickname;
private String email;
private String phone;
private String address;
}
2.2 创建UserMapper类
@Mapper
public interface UserMapper {
@Select("SELECT * FROM sys_user")
List<User> findAll();
}
2.3 创建UserController类
@RestController
public class UserController {
@Autowired
private UserMapper userMapper;
@GetMapping("/")
public List<User> index() {
return userMapper.findAll();
}
}
3、结果