首页 文章 精选 留言 我的

精选列表

搜索[后台管理模板],共10000篇文章
优秀的个人博客,低调大师

Android--后台长期执行定时循环任务

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/79607270 import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.Handler; import android.os.IBinder; import android.os.SystemClock; import java.util.Timer; import java.util.TimerTask; public class MyService extends Service { private Runnable runnable; private Handler handler; private int Time = 1000*3;//周期时间 private int anHour =8*60*60*1000;// 这是8小时的毫秒数 为了少消耗流量和电量,8小时自动更新一次 private Timer timer = new Timer(); @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { super.onCreate(); /** * 方式一:采用Handler的postDelayed(Runnable, long)方法 */ handler = new Handler(); runnable = new Runnable() { @Override public void run() { // handler自带方法实现定时器 System.out.println("33331"); handler.postDelayed(this, 1000*3);//每隔3s执行 } }; handler.postDelayed(runnable, 1000*60);//延时多长时间启动定时器 /** * 方式二:采用timer及TimerTask结合的方法 */ TimerTask timerTask = new TimerTask() { @Override public void run() { System.out.println("99999998"); } }; timer.schedule(timerTask, 1000,//延迟1秒执行 Time);//周期时间 } /** * 方式三:采用AlarmManager机制 */ @Override public int onStartCommand(Intent intent, int flags, int startId) { new Thread(new Runnable() { @Override public void run() { System.out.println("99999988");//这是定时所执行的任务 } }).start(); AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE); long triggerAtTime = SystemClock.elapsedRealtime() + anHour; Intent intent2 = new Intent(this, AutoUpdateReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent2, 0); manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); } } public class AutoUpdateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MyService.class); context.startService(i); } }记得注册广播和服务,建议使用方式三。

优秀的个人博客,低调大师

Python开发微信公众号后台(系列三)

之前有主流的小黄鸡机器人,但是没找到官方的网页版。(小黄鸡提供付费 API )尝试使用http://www.niurenqushi.com/app/simsimi/(虽然事实证明这个网站用的是图灵机器人的 API 而非小黄鸡 API ,后面我们会再谈 API 怎么用) 很简单的一个请求。 http://www.niurenqushi.com/app/simsimi/ajax.aspx?txt= 网址后面加上内容就可以了。 # -*- coding: utf-8 -*- import requests def talk(content): s = requests.session() r = s.post('http://www.niurenqushi.com/app/simsimi/ajax.aspx?txt

优秀的个人博客,低调大师

Python开发微信公众号后台(系列二)

2.3 文本消息操作小例——查快递 上一小节我们已经完成了对文本消息最基础的操作,但是原样返回内容,并没有做任何更多的操作,这一次我们来试试快递接口。 我使用的依然是前文中提到的文章中的 kuaidi100 查快递接口,不过我在本地测试了许多次通过但是 SAE 的服务器依然无法返回正常结果,在网上搜了很久发现时 快递100 封掉了来自 SAE IP 段的请求,也就是说那个接口不能用了,那段代码也废掉了。所以我们只能退而求其次,做一个通过快递单号判断快递公司的功能。 依然是修改weixinInterface.py def POST(self): str_xml = web.data() #获得post来的数据 xml = etree.fromstring(str_xml)#进行XML解析 msgType=xml

优秀的个人博客,低调大师

后台(36)——MyBatis的原始Dao开发方式

探索Android软键盘的疑难杂症 深入探讨Android异步精髓Handler 详解Android主流框架不可或缺的基石 站在源码的肩膀上全解Scroller工作机制 Android多分辨率适配框架(1)— 核心基础 Android多分辨率适配框架(2)— 原理剖析 Android多分辨率适配框架(3)— 使用指南 自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onLayout源码详尽分析 自定义View系列教程04–Draw源码分析及其实践 自定义View系列教程05–示例分析 自定义View系列教程06–详解View的Touch事件处理 自定义View系列教程07–详解ViewGroup分发Touch事件 自定义View系列教程08–滑动冲突的产生及其处理 版权声明 本文原创作者:谷哥的小弟 作者博客地址:http://blog.csdn.net/lfdfhl 使用Mybatis开发Dao,通常有两个方法:原始Dao开发方式和Mapper接口开发方式。 在本篇文章中,我们在上一篇博客的基础上来一起完成原始Dao开发方式。 StudentDto /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com.dao; import java.io.IOException; import java.util.List; import cn.com.bean.Student; public interface StudentDto { public Student findStudentById(int id) throws IOException; public List<Student> findStudentByName(String name) throws IOException; public void insertStudent(Student student) throws IOException; public void deleteStudent(int id) throws IOException; public void updateStudent(Student student) throws IOException; } 在此定义了StudentDto,接下来再看它的实现。 StudentDtoImpl /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com.daoimpl; import java.io.IOException; import java.util.List; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import cn.com.bean.Student; import cn.com.dao.StudentDto; public class StudentDtoImpl implements StudentDto{ private SqlSessionFactory sqlSessionFactory; public StudentDtoImpl(SqlSessionFactory sqlSessionFactory){ this.sqlSessionFactory=sqlSessionFactory; } @Override public Student findStudentById(int id) throws IOException { SqlSession sqlSession=sqlSessionFactory.openSession(); Student student = sqlSession.selectOne("student.findStudentById", id); sqlSession.close(); return student; } @Override public List<Student> findStudentByName(String name) throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); List<Student> list = sqlSession.selectList("student.findStudentByName", name); sqlSession.close(); return list; } @Override public void insertStudent(Student student) throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); sqlSession.insert("student.insertStudent",student); sqlSession.commit(); sqlSession.close(); } @Override public void deleteStudent(int id) throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); sqlSession.delete("student.deleteStudent", id); sqlSession.commit(); sqlSession.close(); } @Override public void updateStudent(Student student) throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); sqlSession.update("student.updateStudent", student); sqlSession.commit(); sqlSession.close(); } } 请务必注意:SqlSession是线程不安全的,所以最好是在方法体内把SqlSession当做局部变量使用。 TestCRUD /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com.test; import java.io.IOException; import java.io.InputStream; import java.util.Date; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Before; import org.junit.Test; import cn.com.bean.Student; import cn.com.dao.StudentDto; import cn.com.daoimpl.StudentDtoImpl; public class TestCRUD { private SqlSessionFactory sqlSessionFactory; @Before public void intiSqlSessionFactory() throws Exception { String resource = "SqlMapConfig.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); } @Test public void findStudentById() throws IOException{ StudentDto studentDto=new StudentDtoImpl(sqlSessionFactory); Student student = studentDto.findStudentById(2); System.out.println(student); } @Test public void findStudentByName() throws IOException { StudentDto studentDto = new StudentDtoImpl(sqlSessionFactory); List<Student> students = studentDto.findStudentByName("结"); for(Student student:students){ System.out.println(student); } } @Test public void deleteStudent() throws IOException{ StudentDto studentDto=new StudentDtoImpl(sqlSessionFactory); studentDto.deleteStudent(3); } @Test public void updateStudent() throws IOException{ StudentDto studentDto=new StudentDtoImpl(sqlSessionFactory); Student student=new Student(); student.setId(4); student.setName("小小木希"); student.setGender("female"); student.setBirthday(new Date()); studentDto.updateStudent(student); } } 除了以上的代码以外,SqlMapConfig.xml和StudentMapper.xml无需修改。 至此,我们在MyBatis中使用传统的DAO的方式就已经全部展示完了。 原始Dao开发方式的问题总结 DAT接口实现类的方法中存在大量冗余的代码 调用sqlsession对象的方法时存在硬编码 由于sqlsession对象的方法的输入参数使用泛型,故在调用sqlsession的方法时传入的变量即使有错在编译阶段也不报错,这不利于程序员开发的。 最后还是附上项目结构图,如下所示:

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册