一 创建了哪些类
二 基础配置
# 服务端口
server.port=8201
# 服务名
spring.application.name=service-obj
# mysql数据库连接
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.43.190:3306/sdgt?characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
# 返回 json 的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
三 mapper层
1 java 代码部分
/**
* @className: HospitalMapper
* @description: 医院数据访问
* @date: 2021/10/4
* @author: cakin
*/
public interface HospitalMapper extends BaseMapper<Hospital> {
}
2 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.baiyee.sdgt.hospital.mapper.HospitalMapper">
</mapper>
四 服务层
1 接口
/**
* @className: HospitalService
* @description: 医院实习接口
* @date: 2021/10/4
* @author: cakin
*/
public interface HospitalService extends IService<Hospital> {
}
2 实现
/**
* @className: HospitalServiceImpl
* @description: 医院实习类
* @date: 2021/10/4
* @author: cakin
*/
@Service
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {
}
五 控制器
@Api(tags = "医院管理")
@RestController
@RequestMapping("/admin/hospital")
//@CrossOrigin
public class HospitalController {
// 注入service
@Autowired
private HospitalService hospitalService;
// 1 查询医院所有信息 http://localhost:8201/admin/hospital/findAll
@ApiOperation(value = "获取所有医院")
@GetMapping("findAll")
public Result findAllHospitalSet() {
// 调用 service 的方法
List<Hospital> list = hospitalService.list();
return Result.ok(list);
}
}
六 测试结果