首页 文章 精选 留言 我的

精选列表

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

11.C++(标准模板库,详细)

(创建于2018/1/2) #ifndef _ITERATOR_DEBUG_LEVEL #define _ITERATOR_DEBUG_LEVEL 0 #else #undef _ITERATOR_DEBUG_LEVEL #define _ITERATOR_DEBUG_LEVEL 0 #endif #include <iostream> #include <string> #include <algorithm> //算法 using namespace std; //STL standard template libary 标准模(mu)板库 C++一部分,编译器自带 //Android NDK支持 //java.lang java.util包中API,java的一部分 //string初始化 void main() { //string由c字符串衍生过来的 string s1 = "craig david"; string s2("7 days"); string s3 = s2; string s4(10,'a'); cout << s4 << endl; system("pause"); } //string遍历 void main() { string s1 = "craig david"; // ^ //1 数组方式 for (int i = 0; i < s1.length(); i++) { cout << s1[i] << endl; } //2 迭代器指针 for (string::iterator it = s1.begin(); it != s1.end(); it++) { cout << *it << " "; } cout << endl; //3 at函数(charAt) // 可能会抛出异常 try { for (int i = 0; i < s1.length() + 3; i++) { cout << s1.at(i) << " "; } } catch (...) { cout << "异常" << endl; } system("pause"); } //string字符串->c字符串转换 void main() { //string -> char* string s1 = "walking away"; const char* c = s1.c_str(); printf("%s\n",c); // string s2 = c; //string->char[] //从string中赋值字符到char[] char arr[50] = {0}; s1.copy(arr,4,0); cout << arr << endl; system("pause"); } //字符串拼接 void main() { string s1 = "alan"; string s2 = "jackson"; //1. string s3 = s1 + s2; string s4 = " pray"; //2. s3.append(s4); cout << s3 << endl; system("pause"); } //字符串查找替换 void main() { string s1 = "apple google apple iphone"; //从0开始查找"google"的位置 int idx = s1.find("google", 0); cout << idx << endl; //统计apple出现的次数 int idx_app = s1.find("apple",0); //npos大于任何有效下标的值 int num = 0; //npos: 如果作为一个返回值(return value)表示没有找到匹配项 while (idx_app != string::npos) { num++; cout << "找到的索引:" << idx_app << endl; idx_app+=5; idx_app = s1.find("apple", idx_app); } cout << num << endl; system("pause"); } void main() { string s1 = "apple google apple iphone"; //0-5(不包含5)替换为jobs s1.replace(0, 5, "jobs"); cout << s1 << endl; //所有apple替换为jobs int idx = s1.find("apple", 0); while (idx != string::npos) { s1.replace(idx, 5, "jobs"); idx += 5; idx = s1.find("apple", idx); } cout << s1 << endl; system("pause"); } //删除(截取)和插入 void main() { string s1 = "apple google apple iphone"; //删除a,找到a所在的指针 string::iterator it = find(s1.begin(),s1.end(),'g'); //只能删除一个字符 s1.erase(it); //开头末尾插入字符串 s1.insert(0, "macos"); s1.insert(s1.length(), " facebook"); cout << s1 << endl; system("pause"); } //java StringBuffer才可变 //String 不可变 //大小写转换 void main() { string s1 = "JASON"; //原始字符串的起始地址,原始字符串的结束地址, 目标字符串的起始地址, 函数名称 transform(s1.begin(), s1.end()-1,s1.begin(), tolower); cout << s1 << endl; transform(s1.begin(), s1.end() - 1, s1.begin(), toupper); cout << s1 << endl; system("pause"); } //----------------------------------------- //容器 //Vector //初始化 #include <vector> void printVector(vector<int> &v) { //通过数组的方式遍历 for (int i = 0; i < v.size(); i++) { cout << v[i] << endl; } } void main() { //1. vector<int> v1; v1.push_back(20); v1.push_back(40); v1.push_back(15); v1.push_back(7); //2. vector<int> v2 = v1; //3.部分复制 vector<int> v3(v1.begin(),v1.begin()+2); printVector(v3); system("pause"); } //添加 删除 void main() { //添加到结尾 vector<int> v1; v1.push_back(20); v1.push_back(40); v1.push_back(15); v1.push_back(7); //访问头部 v1.front() = 11; //访问尾部 v1.back() = 90; //删除结尾的元素 //v1.pop_back(); while (v1.size() > 0) { cout << "末尾的元素:" << v1.back() << endl; v1.pop_back(); } printVector(v1); system("pause"); } //数组的方式 void main() { vector<int> v1; v1.push_back(20); v1.push_back(40); v1.push_back(15); v1.push_back(7); v1[2] = v1[2] +10; //容器等价于动态数组 vector<int> v2(10); for (int i = 0; i < v2.size(); i++) { v2[i] = i + 1; } printVector(v2); system("pause"); } //迭代器遍历 //迭代器的种类(正向,反向迭代器) void main() { vector<int> v1; v1.push_back(20); v1.push_back(40); v1.push_back(15); v1.push_back(7); //正向 for (vector<int>::iterator it = v1.begin(); it < v1.end(); it++) { cout << *it << endl; } cout << "-----------------" << endl; //反向迭代 for (vector<int>::reverse_iterator it = v1.rbegin(); it < v1.rend(); it++) { cout << *it << endl; } system("pause"); } //删除 void main() { vector<int> v1(10); for (int i = 0; i < v1.size(); i++) { v1[i] = i + 1; } //删除指定位置 vector<int>::iterator it = v1.begin(); it += 3; v1.erase(it); //distance(v1.begin(), it); //删除区间 v1.erase(v1.begin(), v1.begin() + 3); for (vector<int>::iterator it = v1.begin(); it < v1.end(); it++) { if (*it == 5) { printf("%x\n", it); vector<int>::iterator tmp = v1.erase(it); //注意以后开发中编译器版本问题 printf("%x,%x\n",it,tmp); } } //插入 v1.insert(v1.begin() + 2, 100); v1.insert(v1.end() - 1, 200); printVector(v1); system("pause"); } //双向队列 #include <deque> void printDeque(deque<int>& q) { for (int i = 0; i < q.size(); i++) { cout << q[i] << endl; } } void main() { deque<int> d1; //添加到尾部 d1.push_back(2); d1.push_back(10); //添加到头部 d1.push_front(-90); d1.push_front(-30); //printDeque(d1); //cout << d1.front() << endl; //cout << d1.back() << endl; //两个方向弹出 //d1.pop_back(); //d1.pop_front(); printDeque(d1); //查找第一个-90元素索引位置,无需遍历 deque<int>::iterator it = find(d1.begin(),d1.end(),-90); if (it != d1.end()) { int idx = distance(d1.begin(), it); cout << "索引位置为:" << idx << endl; } system("pause"); } //数据结构 算法 分离 //Collections.shuff sort

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

MongoDB 安全 checklist 及最优配置模板

云数据库 MongoDB 版 基于飞天分布式系统和高性能存储,提供三节点副本集的高可用架构,容灾切换,故障迁移完全透明化。并提供专业的数据库在线扩容、备份回滚、性能优化等解决方案。 了解更多 最近 MongoDB “赎金事件”闹得沸沸扬扬,不少公网上裸奔的 MongoDB 中招,有兴趣的同学可以看下耗子叔写的从 MONGODB “赎金事件” 看安全问题,中招的主要原因还是因为用户的安全意识比较薄弱,部署的 MongoDB 完全没有任何安全防护,可以通过公网访问,并且没有开启鉴权。 MongoDB 官方文档在安全方面做了很多总结,出了一个MongoDB Security Checklist,但从这次中招的规模来看,大部分用户并没有认真看过这个文档,这次事件也刚好是一个数据库安全科普的好机会,希望所有的数据库用户都要重视自己的数据安全。 Mon

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

后台(41)——MyBatis的动态SQL

探索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可利用动态SQL极大的简化SQL语句的拼接。 在此介绍几种MyBatis中常用的动态SQL where和if 还记得我们之前有一个查询学生的例子么? <select id="findStudentList" parameterType="cn.com.StudentQueryVO" resultType="cn.com.StudentCustom"> SELECT * FROM student WHERE gender=#{studentCustom.gender} and name like '%${studentCustom.name}%' </select> 猛地一看这个SQL没啥问题,但是仔细一想又不对,studentCustom有没有可能为null呢?studentCustom.gender和studentCustom.name有没有可能为null呢?当然是有的,那么我们可以怎么处理一下呢?此时就可以用<where>和<if>,请看: <select id="findStudentList" parameterType="cn.com.StudentQueryVO" resultType="cn.com.StudentCustom"> SELECT * FROM student <where> <if test="studentCustom!=null"> <if test="studentCustom.gender!=null"> and gender=#{studentCustom.gender} </if> <if test="studentCustom.name!=null"> and name like '%${studentCustom.name}%' </if> </if> </where> </select> 在此利用标签<where>和<if>对应了某些查询条件为null的情况。有人或许有疑问,如果两个查询条件都满足的话在这个sql中岂不是有两个and了?甭担心,这种情形下MyBatis会自动删除掉掉第一个and sql 其实,我们还可以把刚才这个例子继续优化一下利用<sql>提取出<if>作为sql片段从而提高代码的复用性 <sql id="findStudentList_if"> <if test="studentCustom!=null"> <if test="studentCustom.gender!=null"> and gender=#{studentCustom.gender} </if> <if test="studentCustom.name!=null"> and name like '%${studentCustom.name}%' </if> </if> </sql> 然后在查询语句中引用该sql片段即可 <select id="findStudentList" parameterType="cn.com.StudentQueryVO" resultType="cn.com.StudentCustom"> SELECT * FROM student <where> <include refid="findStudentList_if"></include> </where> </select> foreach 来看一种需求:查询出id为2、4、7的学生信息,我们可以这么写sql SELECT * FROM student WHERE (id=2 OR id=4 OR id=7) 那么这个sql在MyBatis里又该怎么写呢? 在此可采用<foreach>标签来拼装这个条件(id=2 OR id=4 OR id=7) 首先,我们在StudentQueryVO中定义一个字段idsList用于传递这几个id值 /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com; import java.util.List; //自定义的包装类型的pojo public class StudentQueryVO { private List<Integer> idsList; //用户查询条件 private StudentCustom studentCustom; public StudentCustom getStudentCustom() { return studentCustom; } public void setStudentCustom(StudentCustom studentCustom) { this.studentCustom = studentCustom; } public List<Integer> getIdsList() { return idsList; } public void setIdsList(List<Integer> idsList) { this.idsList = idsList; } //其他查询条件,比如教师,课程,学校等等 } 再来看mapper.xml <sql id="findStudentList_ids_if"> <if test="idsList!=null"> <foreach collection="idsList" item="student_id" open="(" close=")" separator="OR"> id=#{student_id} </foreach> </if> </sql> <select id="findStudentList" parameterType="cn.com.StudentQueryVO" resultType="cn.com.StudentCustom"> SELECT * FROM student <where> <include refid="findStudentList_ids_if"></include> </where> </select> 重点来看这个<foreach>标签 collection表示pojo中的集合 item表示遍历时集合中每个元素 open表示组拼后的语句的开头 close表示组拼后的语句的结尾 separator表示每个部门的连接符 最后来看测试代码 @Test public void findStudentList() throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class); StudentQueryVO studentQueryVO=new StudentQueryVO(); List<Integer> idsList=new ArrayList<Integer>(); idsList.add(2); idsList.add(4); idsList.add(7); studentQueryVO.setIdsList(idsList); List<StudentCustom> studentList = studentMapper.findStudentList(studentQueryVO); for (int i = 0; i <studentList.size(); i++) { StudentCustom sc = studentList.get(i); System.out.println(sc); } sqlSession.commit(); sqlSession.close(); } 其实,这些动态SQL并不难,也不需要死记硬背。但是要把握住总的原则和目标:利用动态SQL拼装成原始的sql语句。在实际开发时也可以先写出原始sql语句再写到mapper.xml中

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

后台(39)——MyBatis输入映射parameterType

探索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通过parameterType对sql的输入参数进行定义,参数的类型可以是:基本类型、HashMap、pojo。在此分别介绍为parameterType传入三种类型的不同处理方式。 基本类型 其实,从这个MyBatis学习系列开始,我们已经多次为parameterType传入基本类型的参数,比如int 、long等。故,在此不再赘述,请参见前几篇博客的示例。 HashMap 首先来看mapper.mxl中的sql语句 <select id="findStudentByHashMap" parameterType="hashmap" resultType="cn.com.Student"> SELECT * FROM student WHERE id=#{id} and name like '%${name}%' </select> 嗯哼,看到没有:我们为parameterType指定的输入类型是hashmap。在sql语句中从hashmap中取出id和name作为查询条件 接下来瞅瞅mapper.java中的定义 public List<Student> findStudentByHashMap(HashMap<String, Object> hashMap); 最后,再来看看测试代码: @Test public void findStudentByHashMap() throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class); HashMap<String, Object> hashMap=new HashMap<String, Object>(); hashMap.put("id", 7); hashMap.put("name", "木"); List<Student> studentList = studentMapper.findStudentByHashMap(hashMap); for (int i = 0; i <studentList.size(); i++) { Student student = studentList.get(i); System.out.println(student); } sqlSession.commit(); sqlSession.close(); } 在此,创建一个HashMap且指定两个key:id和name并为它们赋值;然后执行查询即可。 pojo 有时候,我们需要执行一些复杂的查询,比如:查询的条件不仅包括学生查询条件还包括其它的查询条件(比如:课程,教师,学校等)。此时,可以使用自定义pojo传递输入参数。 首先,定义一个Student的扩展类 /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com; //Student的扩展类 public class StudentCustom extends Student{ } 再自定义包装类型的pojo /** * 本文作者:谷哥的小弟 * 博客地址:http://blog.csdn.net/lfdfhl */ package cn.com; //自定义的包装类型的pojo public class StudentQueryVO { //用户查询条件 private StudentCustom studentCustom; public StudentCustom getStudentCustom() { return studentCustom; } public void setStudentCustom(StudentCustom studentCustom) { this.studentCustom = studentCustom; } //其他查询条件,比如教师,课程,学校等等 } 在该pojo中不仅包括与学生相关的查询条件,还有与教师,课程,学校有关的查询条件。 接下来请看mapper.xml <select id="findStudentList" parameterType="cn.com.StudentQueryVO" resultType="cn.com.StudentCustom"> SELECT * FROM student WHERE gender=#{studentCustom.gender} and name like '%${studentCustom.name}%' </select> 嗯哼,看到了吧:我们将自定义的包装类型的pojo作为输入参数设置给parameterType;然后取出输入参数StudentQueryVO中的studentCustom的gender和name作为条件查询。 再来瞅瞅mapper.java中的定义 public List<StudentCustom> findStudentList(StudentQueryVO studentQueryVO); 最后,请看测试代码: @Test public void findStudentList() throws IOException { SqlSession sqlSession = sqlSessionFactory.openSession(); StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class); StudentQueryVO studentQueryVO=new StudentQueryVO(); StudentCustom studentCustom=new StudentCustom(); studentCustom.setGender("female"); studentCustom.setName("木"); studentQueryVO.setStudentCustom(studentCustom); List<StudentCustom> studentList = studentMapper.findStudentList(studentQueryVO); for (int i = 0; i <studentList.size(); i++) { StudentCustom sc = studentList.get(i); System.out.println(sc); } sqlSession.commit(); sqlSession.close(); }

资源下载

更多资源
Mario

Mario

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

Nacos

Nacos

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

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

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

用户登录
用户注册