实现最简单的数据库查询,跑通流程
Controller
@RestController
@RequestMapping("/api/tool")
@RequiredArgsConstructor
public class ToolController {
@Autowired
private ToolService toolService;
@ApiOperation(value = "查询")
@GetMapping(value = "/info")
public Result<String> getToolInfo(@RequestParam("userId") String userId) {
return Result.ok(toolService.getFirstApi(userId));
}
}
Service
public interface ToolService {
String getFirstApi( String userId);
}
ServiceImpl
@RequiredArgsConstructor
@Service
public class ToolServiceImpl implements ToolService {
@Autowired
private ToolMapper toolMapper;
@Override
public String getFirstApi(String userId) {
return toolMapper.getFirstApi(userId);
}
}
Dao/Mapper
@Component
public interface ToolMapper {
String getFirstApi(@Param("userId") String userId);
}
Mapper.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="com.***.**.common.dao.mapper.ToolMapper">
<select id="getFirstApi" resultType="String">
select api
from api_info
where id = #{userId}
</select>
</mapper>
最终结果: