当前位置: 首页 > news >正文

成都新站软件快速排名中铁建设集团有限公司天津分公司

成都新站软件快速排名,中铁建设集团有限公司天津分公司,网站备案名称能重复吗,网站建设350元SpringBootSqlServer查询接口 文章目录 SpringBootSqlServer查询接口1. pom环境配置2. common工具包3. 实体类接口映射4. Service层Controller层 需求#xff1a;根据站号查询前一个小时的所有数据#xff0c;将数据返回格式为MapString,ListMapString,StringSqlServer查询接口 文章目录 SpringBootSqlServer查询接口1. pom环境配置2. common工具包3. 实体类接口映射4. Service层Controller层 需求根据站号查询前一个小时的所有数据将数据返回格式为MapString,ListMapString,String即 首先是四个参数每个参数中有12条数据(每5分钟一条数据一小时12条)每条数据有参数日期时间该参数的值。 要求结果处理如下图 1. pom环境配置 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.zhwy/groupIdartifactIdbdly-3dwind-query/artifactIdpackagingjar/packagingversion1.0-SNAPSHOT/versionnamebdly-3dwind-query Maven Webapp/nameurlhttp://maven.apache.org/urlparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion1.5.6.RELEASE/version/parentdependencies!--SQLServer连接--dependencygroupIdcom.microsoft.sqlserver/groupIdartifactIdsqljdbc4/artifactIdversion4.0/version/dependency!--Lombok引入--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactId/dependency!--myabtis--dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion2.3.0/version/dependency!--web 支持--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!--jsp页面使用jstl标签--dependencygroupIdjavax.servlet/groupIdartifactIdjstl/artifactId/dependency!--用于编译jsp--dependencygroupIdorg.apache.tomcat.embed/groupIdartifactIdtomcat-embed-jasper/artifactIdscopeprovided/scope/dependency!--springboot用JPA连接mysql数据库--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdscoperuntime/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion3.8.1/versionscopetest/scope/dependency/dependenciesbuildfinalNamebdly-3dwind-query/finalNamepluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdexecutionsexecutiongoalsgoalrepackage/goal/goals/execution/executions/plugin/plugins/build /project2. common工具包 common工具包 结果返回Result.java package com.zhwy.common;import lombok.Data;/*** author xjz_2002* version 1.0*/ Data public class ResultT {//返回码private Integer code;//返回消息private String message;//返回数据private T data;public Result(){}// 返回数据protected static T ResultT build(T data) {ResultT result new ResultT();if (data ! null)result.setData(data);return result;}public static T ResultT build(T body, Integer code, String message) {ResultT result build(body);result.setCode(code);result.setMessage(message);return result;}public static T ResultT build(T body, ResultCodeEnum resultCodeEnum) {ResultT result build(body);result.setCode(resultCodeEnum.getCode());result.setMessage(resultCodeEnum.getMessage());return result;}public staticT ResultT ok(){return Result.ok(null);}/*** 操作成功* param data* param T* return*/public staticT ResultT ok(T data){ResultT result build(data);return build(data, ResultCodeEnum.SUCCESS);}public staticT ResultT fail(){return Result.fail(null);}/*** 操作失败* param data* param T* return*/public staticT ResultT fail(T data){ResultT result build(data);return build(data, ResultCodeEnum.FAIL);}public ResultT message(String msg){this.setMessage(msg);return this;}public ResultT code(Integer code){this.setCode(code);return this;} }DataType 枚举类 package com.zhwy.common;import com.zhwy.pojo.SurfChnMulMin;import java.util.Map;import static com.zhwy.common.Tool.toStr;/*** author xjz_2002* version 1.0*/ public enum DataType {PRE(pre), TEM(tem), RHU(rhu), WIN(win);private final String code;DataType(String code) {this.code code;}// 基于数据类型填充数据的方法public void populateData(MapString, String dataMap, SurfChnMulMin scmm) {switch (this) {case PRE:dataMap.put(code, toStr(scmm.getPre()));break;case TEM:dataMap.put(code, toStr(scmm.getTem()));break;case RHU:dataMap.put(code, toStr(scmm.getRhu()));break;case WIN:dataMap.put(win_D, toStr(scmm.getWinDAvg2mi()));dataMap.put(win_S, toStr(scmm.getWinSAvg2mi()));break;// 根据需要添加更多数据类型}} } ResultCodeEnum 枚举返回结果类 package com.zhwy.common;import lombok.Getter;/*** author xjz_2002* version 1.0*/ Getter public enum ResultCodeEnum {SUCCESS(200,成功),FAIL(201, 失败),SERVICE_ERROR(2012, 服务异常),DATA_ERROR(204, 数据异常),ILLEGAL_REQUEST(205, 非法请求),REPEAT_SUBMIT(206, 重复提交),ARGUMENT_VALID_ERROR(210, 参数校验异常),LOGIN_AUTH(208, 未登陆),PERMISSION(209, 没有权限),ACCOUNT_ERROR(214, 账号不正确),PASSWORD_ERROR(215, 密码不正确),LOGIN_MOBLE_ERROR( 216, 账号不正确),ACCOUNT_STOP( 217, 账号已停用),NODE_ERROR( 218, 该节点下有子节点不可以删除);private Integer code;private String message;private ResultCodeEnum(Integer code, String message) {this.code code;this.message message;}} Tool 工具类 package com.zhwy.common;import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;/*** author xjz_2002* version 1.0*/ public class Tool {public static String toStr(Object obj) {String result ;if (obj null) {result 0;} else {result obj.toString();}return result;}} 3. 实体类接口映射 pojo实体类 SurfChnMulMin.java package com.zhwy.pojo;import com.fasterxml.jackson.annotation.JsonFormat;import java.io.Serializable; import java.util.Date;public class SurfChnMulMin implements Serializable {private String stationIdC;private String stationName;private Date datetime;private Double pre;private Double tem;private Double rhu;private Double winDAvg2mi;private Double winSAvg2mi;public SurfChnMulMin() {}public SurfChnMulMin(String stationIdC, String stationName, Date datetime, Double pre, Double tem, Double rhu, Double winDAvg2mi, Double winSAvg2mi) {this.stationIdC stationIdC;this.stationName stationName;this.datetime datetime;this.pre pre;this.tem tem;this.rhu rhu;this.winDAvg2mi winDAvg2mi;this.winSAvg2mi winSAvg2mi;}public String getStationIdC() {return stationIdC;}public void setStationIdC(String stationIdC) {this.stationIdC stationIdC;}public String getStationName() {return stationName;}public void setStationName(String stationName) {this.stationName stationName;}JsonFormat(pattern yyyy-MM-dd HH:mm:ss,timezoneGMT8)public Date getDatetime() {return datetime;}JsonFormat(pattern yyyy-MM-dd HH:mm:ss,timezoneGMT8)public void setDatetime(Date datetime) {this.datetime datetime;}public Double getPre() {return pre;}public void setPre(Double pre) {this.pre pre;}public Double getTem() {return tem;}public void setTem(Double tem) {this.tem tem;}public Double getRhu() {return rhu;}public void setRhu(Double rhu) {this.rhu rhu;}public Double getWinDAvg2mi() {return winDAvg2mi;}public void setWinDAvg2mi(Double winDAvg2mi) {this.winDAvg2mi winDAvg2mi;}public Double getWinSAvg2mi() {return winSAvg2mi;}public void setWinSAvg2mi(Double winSAvg2mi) {this.winSAvg2mi winSAvg2mi;} } Mapper接口 ScmmMapper package com.zhwy.mapper;import com.zhwy.pojo.SurfChnMulMin; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param;import java.util.Date; import java.util.List;/*** author xjz_2002* version 1.0*/ Mapper public interface ScmmMapper{//获取最近一小时所有数据ListSurfChnMulMin getScmmList(Param(startTime) String startTime,Param(endTime) String endTime,Param(staId) String staId);//获取最新时间Date getScmmNewDate(Param(staId) String staId);} Resouces/mapper/ScmmMapper.xml ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.zhwy.mapper.ScmmMapperselect idgetScmmList resultTypecom.zhwy.pojo.SurfChnMulMinSELECT Station_Id_C,Station_Name,Datetime,PRE,RHU,TEM,WIN_D_Avg_2mi,WIN_S_Avg_2miFROM SURF_CHN_MUL_MINWHERE (Datetime gt; #{startTime} AND Datetime lt; #{endTime})AND Station_Id_C #{staId}/selectselect idgetScmmNewDate resultTypejava.util.DateSELECT DatetimeFROM SURF_CHN_MUL_MINWHERE Station_Id_C #{staId}AND Datetime (SELECT MAX(Datetime)FROM SURF_CHN_MUL_MIN)/select/mapper 4. Service层Controller层 service层 ScmmService.java package com.zhwy.service;import com.zhwy.common.Result; import com.zhwy.mapper.ScmmMapper; import com.zhwy.pojo.SurfChnMulMin; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List;/*** author xjz_2002* version 1.0*/ Service public class ScmmService {ResourceScmmMapper scmmMapper;// 根据时间段和站号获取天气参数public ListSurfChnMulMin getScmmByDateAndStaId(String times, String staId) {DateTimeFormatter dtf DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss);LocalDateTime endTimeDate LocalDateTime.parse(times, dtf);LocalDateTime startTimeDate endTimeDate.minusHours(1);String endTime endTimeDate.format(dtf);String startTime startTimeDate.format(dtf);return scmmMapper.getScmmList(startTime,endTime,staId);}//根据站号获取DB中最新时间public String getScmmNewDate(String staId){SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);Date scmmNewDate scmmMapper.getScmmNewDate(staId);return sdf.format(scmmNewDate);}} Controller层 ScmmController.java package com.zhwy.controller;import com.zhwy.common.DataType; import com.zhwy.common.Result; import com.zhwy.pojo.SurfChnMulMin; import com.zhwy.service.ScmmService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.*;/*** author xjz_2002* version 1.0*/ RestController public class ScmmController {ResourceScmmService scmmService;// 根据时间段和站号获取天气参数RequestMapping(value /getScmmByDateAndStaIdEnum)public Result getScmmByDateAndStaId(String staId) {//获取数据库中最新日期时间String times scmmService.getScmmNewDate(staId);//根据站号查询DB中近一小时所有数据ListSurfChnMulMin scmmList scmmService.getScmmByDateAndStaId(times, staId);//对返回结果进行格式处理MapString, ListMapString, String resultMap new HashMap();SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);for (DataType dataType : DataType.values()) {//dataList存放近一小时数据根据天气参数返回该参数的值和日期时间ListMapString, String dataList new ArrayList();//遍历近一小时所有数据进行处理for (SurfChnMulMin scmm : scmmList) {MapString, String dataMap new HashMap();dataMap.put(datetime, sdf.format(scmm.getDatetime()));dataType.populateData(dataMap, scmm);dataList.add(dataMap);}resultMap.put(dataType.name().toLowerCase(), dataList);}return Result.ok(resultMap);} } application.yml 配置文件 效果截图
http://www.zqtcl.cn/news/446638/

相关文章:

  • 网站建设海淀区网站特殊字体
  • 电子商务网站建设情况国风网页设计欣赏
  • 海拉尔网站建设+网站设计徐州模板建站定制网站
  • 做网站诱导充值犯法吗折叠分类目录模板wordpress
  • 企业网站建设的平台怎样建网站买东西
  • 免费推广工具有哪些上海优化营商环境
  • 模板网站怎么修改下载的字体如何安装到wordpress
  • 中国建设资格注册中心网站杭州市建设信用网官网
  • 国外网站搭建平台wordpress+行间距插件
  • 做网站买那种服务器wordpress商店插件
  • dw网站开发流程做影视网站怎么
  • 建好的网站在哪里免费的app软件大全
  • 建设银行信用卡境外网站盗刷电子商务专业是学什么的
  • asp.net做电商网站设计徐州做网站费用
  • 网站怎么发布做微商wordpress 主页显示多图
  • 国外做宠物用品的网站安徽网新科技有限公司官网
  • 辣条类网站建设规划书南阳网站推广优化公司
  • 帝国网站做地域标签seo关键词排名查询
  • 西安网站建设xs029免费代理ip最新
  • 网站建设不挣钱海盐建设局网站
  • 潍坊做网站张家口最近一个月的热点事件
  • 套模板的网站多少钱公司付的网站费怎么做分录
  • 做ps找图的网站有哪些响应式设计是什么意思
  • 家教网站建设的推广猪八戒网站做私活赚钱吗
  • 男女做那种的视频网站asp.net做网站怎么样
  • 给企业做网站怎么收钱郑州网站顾问
  • readme.md做网站设计网页的快捷网站
  • 做双语网站用什么cms系统好百度后台管理
  • 什么网站可以做试卷企业的oa管理系统
  • 经典网站模板自己做pc网站建设