srpingboot接口 流程
Controller
=> Service
=> Impl
=> Dao
=> xml
- TestEntity
@Data
public class TestEntity {
private String testId;
private String testName;
}
- Controller 接口类
@RestController
@RequestMapping(value = "test")
public class TestController {
@Resource
private TestService testService;
@RequestMapping(value = "get")
public List<TestEntity> test() {
return testService.testFindAll();
}
}
- testService
public interface testService {
List<TestEntity> testFindAll();
}
- Impl
@Service
public class testServiceImpl implements testService {
@Autowired
private TestDao testDao;
@Override
public List<TestEntity> testFindAll() {
return testDao.testFindAll();
}
}
- Dao
@Mapper
public interface testDao{
List<TestEntity> testFindAll();
}
- xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Dao路径 testDao">
<!-- 通用查询映射结果 -->
<resultMap id="testResultMap" type="。。。。TestEntity">
<result column="test_id" property="testId"/>
<result column="test_name" property="testName"/>
<result column="keyword_status" property="keywordStatus"/>
<result column="create_time" property="createTime"/>
</resultMap>
<select id="testFindAll" resultMap="testResultMap">
select * from test
</select>
</mapper>
- test 数据库表格式
/*
Navicat Premium Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 100137
Source Host : localhost:3306
Source Schema : blog
Target Server Type : MySQL
Target Server Version : 100137
File Encoding : 65001
Date: 13/10/2020 16:47:48
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`test_id` int(11) NOT NULL,
`test_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`test_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
SET FOREIGN_KEY_CHECKS = 1;