栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

代码层(spring-could)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

代码层(spring-could)

代码层(spring-could)

感觉与以前学的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 BaseMapper{
//下面这个注解用之后,.xml文件就用不到了

    ExportStateEntity selectExportState();
}
2.Service层

代码如下(示例):……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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/963720.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号