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

电商 企业网站 福州自己怎么做直播网站吗

电商 企业网站 福州,自己怎么做直播网站吗,网站建设企业站,营销网络建设将给三夫户外带来哪些有益的影响?自定义starter案例——统计独立IP访问次数 文章目录 自定义starter案例——统计独立IP访问次数ip计数业务功能开发定时任务报表开发使用属性配置功能设置功能参数配置调整 自定义拦截器开启yml提示功能 ip计数业务功能开发 public class IpCountService {private MapString…自定义starter案例——统计独立IP访问次数 文章目录 自定义starter案例——统计独立IP访问次数ip计数业务功能开发定时任务报表开发使用属性配置功能设置功能参数配置调整 自定义拦截器开启yml提示功能 ip计数业务功能开发 public class IpCountService {private MapString,Integer ipCountMap new HashMapString,Integer();Autowired// 当前的request对象的诸如工作由当前的starter的工程提供自动装配private HttpServletRequest httpServletRequest;public void count(){// 每次调用当前操作就记录当前访问的ip然后累加访问次数// 1.获取当前操作的ip地址String ip httpServletRequest.getRemoteAddr();System.out.println(---------------------------------- ip);// 2.根据ip地址从map取值并递增ipCountMap.put(ip,ipCountMap.get(ip)null? 01 : ipCountMap.get(ip) 1);} } 使用import注入bean也可以 public class IpAutoCinfiguration {Beanpublic IpCountService ipCountService(){return new IpCountService();} } org.springframework.boot.autoconfigure.EnableAutoConfiguration\ cn.itcast.autoconfig.IpAutoCinfigurAutowiredprivate IpCountService ipCountService;GetMapping(/{currentPage}/{pageSize})public R getPage(PathVariable int currentPage,PathVariable int pageSize,Book book){ipCountService.count();IPageBook page bookService.getPage(currentPage, pageSize,book);// 如果当前页码值大于总页码值那么重新执行查询操作使用最大页码值作为当前页码值if (currentPage page.getPages()){page bookService.getPage((int)page.getPages(), pageSize,book);}return new R(true,page);} 定时任务报表开发 EnableScheduling public class IpAutoCinfiguration {Beanpublic IpCountService ipCountService(){return new IpCountService();} }Scheduled(cron 0/5 * * * * ?)public void print(){System.out.println( ip访问监控);System.out.println(-----ip-address--------);for (Map.EntryString, Integer entry : ipCountMap.entrySet()) {String key entry.getKey();Integer value entry.getValue();System.out.println(String.format(|%18s |%5d |,key,value));}System.out.println(-----------------------);}使用属性配置功能设置功能参数 ConfigurationProperties(prefix tools.ip) public class IpProperties {/*** 日志的显示周期*/private Long cycle 5L;/*** 是否周期内重置数据*/private Boolean cycleReset false;/*** 日志的输出模式 detail:详细模式simple极简模式*/private String model LogModel.DETAIL.value;public enum LogModel{DETAIL(detail),SIMPLE(simple);private String value;LogModel(String value){this.value value;}public String getValue(){return value;}}public Long getCycle() {return cycle;}public void setCycle(Long cycle) {this.cycle cycle;}public Boolean getCycleReset() {return cycleReset;}public void setCycleReset(Boolean cycleReset) {this.cycleReset cycleReset;}public String getModel() {return model;}public void setModel(String model) {this.model model;} } EnableScheduling EnableConfigurationProperties(IpProperties.class) public class IpAutoCinfiguration {Beanpublic IpCountService ipCountService(){return new IpCountService();} } Autowiredprivate IpProperties ipProperties;Scheduled(cron 0/5 * * * * ?)public void print(){if(ipProperties.getModel().equals(IpProperties.LogModel.DETAIL.getValue())){System.out.println( ip访问监控);System.out.println(-----ip-address-------num--);for (Map.EntryString, Integer entry : ipCountMap.entrySet()) {String key entry.getKey();Integer value entry.getValue();System.out.println(String.format(|%18s |%5d |,key,value));}System.out.println(-----------------------);} else if (ipProperties.getModel().equals(IpProperties.LogModel.SIMPLE.getValue())) {System.out.println( ip访问监控);System.out.println(-----ip-address-----);for (String key : ipCountMap.keySet()) {System.out.println(String.format(|%18s |,key));}System.out.println(--------------------);}if(ipProperties.getCycleReset()){ipCountMap.clear();}}tools:ip: # cycle: 1 # cycle-reset: true # model: simple配置调整 自定义bean名称原因如下 因为我们的周期属性是要配置在cron表达式中的但是如何获取配置的属性需要读取到bean但是直接找bean的话名字特别长而且这个bean的名字和beanName的生成器生成的名称恰巧与我们的表达式冲突所以就曲线救国自己给bean起个名字。 但是自己起个名字就出现了另一个问题我们的配置类上以前是使用EnableConfigurationProperties(IpProperties.class)注册的IpProperties的bean现在IpProperties被注册了两次bean又有了新的问题所以我们在IpAutoCinfiguration上把以前的EnableConfigurationProperties的方式换成Import的方式导入bean。 自定义拦截器 public class IpCountInterceptor implements HandlerInterceptor {Autowiredprivate IpCountService ipCountService;Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {ipCountService.count();return true;}} Configuration public class SpringMvcConfig implements WebMvcConfigurer {Beanpublic IpCountInterceptor ipCountInterceptor(){return new IpCountInterceptor();}Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(ipCountInterceptor()).addPathPatterns(/**);} } 写完后要在启动类上加上拦截器哟使用Import加进去。 EnableScheduling //EnableConfigurationProperties(IpProperties.class) Import({IpProperties.class, IpCountInterceptor.class, SpringMvcConfig.class}) public class IpAutoCinfiguration {Beanpublic IpCountService ipCountService(){return new IpCountService();} } 开启yml提示功能 !-- dependency-- !-- groupIdorg.springframework.boot/groupId-- !-- artifactIdspring-boot-configuration-processor/artifactId-- !-- /dependency--用这个坐标生成spring-configuration-metadata也就是加上这个坐标然后clean-install,就会生成这个文件把这个文件从target目录中找到并且提出来放到我们的配置目录下这个坐标就可以注释了因为上线用不到。 hints: [{name: tools.ip.model,values: [{value: detail,description: 详细模式.},{value: simple,description: 极简模式.}]}]提示功能默认是[]自己照着样子配就行了。
http://www.yutouwan.com/news/314601/

相关文章:

  • 做境外网站私人网站免费观看
  • 使用html5做语音标注网站wordpress怎样禁止采集
  • 本地江苏网站建设有什么可以接单做的网站
  • 网站优化无限关键词设置洛阳网站建设哪家公司好
  • 做非法网站怎么规避北京如何做网站
  • 怎么做国外的网站台州网页设计公司
  • 移动版网站开发网站设计的基本过程
  • 瑞安企业做网站直播开发平台
  • 本地网站建设电话可以接项目做的网站
  • 建设虚拟网站长沙网站制作服务
  • 知名自适应网站建设哪家好建设机械网站方案设计
  • 企业网站托管和网站建设服务商电商网站可以用dw做
  • 制作好网站wordpress网站微信支付
  • 淘宝客如何做免费的网站乐山住房和城乡建设厅网站
  • 做网站用什么版本系统建设网站的企业费用
  • 企业网站的开发wordpress windows
  • 做网站需要绑定电脑ip吗河南安阳市有几个县
  • 南沙定制型网站建设企业开办全程网办
  • 网站建设模板是什么长春网站建设模板制作
  • 网站建设费用能否计入开办费ui页面设计规范
  • 河南城乡与住房建设厅网站网站排名要怎么做
  • 东莞建域名网站廊坊公司做网站
  • 找做网站的客户海外教育集团网站建设
  • 歌曲网站模板实业 东莞网站建设
  • wordpress 面包插件如何进行网站的seo
  • 个人网站做交易类的赚钱吗程序员代做网站违法
  • 枣庄市住房和城乡建设局网站建设网站过程视频
  • 农业信息门户网站建设方案传统生意转型做那个网站好
  • 网站建设费用核算科目中企动力员工感受
  • 如何设置企业网站做二手网站有哪些问题