感觉与以前学的ssm差不多
主要是Swagger注解
文章目录
- 代码层(spring-could)
- @[TOC](文章目录)
- 一、;类前注释
- 二、类
- 1.实体类
- 2.Dao层
- 2.Service层
- 3.Controller层
- 总结
二、类 1.实体类
代码如下(示例):……Entity
@Data
@TableName("rmon_common_platform") //数据库表名
public class CommonPlatformEntity implements Serializable{//这个接口我看了一下没内容就是一个公共空接口
private static final long serialVersionUID = 1L;//版式id???
@ApiModelProperty(value = "字段名汉字",required = true,hidden = true)
//注解是添加数据属性的,required的是否必须,ture表示必须,hidden表示是否隐藏
@TableId(value="id",type= IdType.ASSIGN_UUID)//主键注解,非主键无此
private String id;//字段相对应的成员变量
}
2.Dao层
代码如下(示例):……Dao,.xml和以前差不多
@Mapper public interface CommonPlatformDao extends BaseMapper2.Service层{ //下面这个注解用之后,.xml文件就用不到了 ExportStateEntity selectExportState(); }
代码如下(示例):……Service //……ServiceImpl
public interface PointCoordinateService {
List selectPointList() throws ServiceException;//抛出异常
}
@Slf4j
@Service("PointCoordinateService")
public class PointCoordinateServiceImpl implements PointCoordinateService {
@Autowired
private PointCoordinateDao pointCoordinateDao;
@Override
public List selectPointList() throws ServiceException {
List pointCoordinateList = null;
try {
pointCoordinateList = pointCoordinateDao.selectPointList();
log.info("显示单点位置信息{}",pointCoordinateList);
} catch (Exception e) {
throw new ServiceException(e);
}
return pointCoordinateList;
}
}
3.Controller层
代码如下(示例):……Controller
@Slf4j
@Api(tags = "FPSO API")
@RestController
@RequestMapping("rmon/pointPull")
public class PointPullController {
@Autowired
private PointPullService pointPullService;
@ApiOperation(value = "查询单点状态拉力信息",notes = "查询最新一条单点状态拉力信息")
@ApiResponses({
@ApiResponse(code=200,message = "操作成功",response = PointPullEntity.class)
})
@ApiImplicitParams({
@ApiImplicitParam(name = "param1",value = "参数1",dataType = "String", paramType = "query", required = true, example = "ep181"),
@ApiImplicitParam(name = "param2",value = "参数2",dataType = "Integer", paramType = "query", required = true, example = "4")
})
@GetMapping("/getPointPull")
public Result getPointPull(@RequestParam String param1,
@RequestParam Integer param2) throws ControllerException {
try {
PointPullEntity pointPullEntity = pointPullService.selectPointPull(param1,param2);
return Result.succeed(pointPullEntity);
} catch (Exception e) {
throw new ControllerException(e);
}
}
}
总结
新入职留存1



