导入了一个工程,编译什么的都还好,但是报了一个XML的错误。 cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. 具体错误如下: Multiple annotations found at this line: – cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. – schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 根据错误提示,有可能是http://code.alibabatech.com/schema/dubbo/dubbo.xsd这个文档找不到或者打不开,于是百度了一下,发现类似问题的问还是比较多的,比较轻松找到解决办法。大致的思路是,到网上下载一个dubbo.xsd文件,其实在dubbo的jar包里就有,直接解压出来就好,放到本地目录,然后在Eclipse里配置上关联关系,让Eclipse能找到这个文件即可。 1、下载一个dubbo.xsd文件; 2、在windows->preferrence->xml->xmlcatalogadd->catalog entry ->file system 选择刚刚下载的文件路径; 3、修改key值和配置文件的http://code.alibabatech.com/schema/dubbo/dubbo.xsd 相同保存。 4、在xml文件右键validate就可以k解决了。 后记:有其它的xsd文件找不到的情况,也可以按照类似的方法解决。 from:https://blog.csdn.net/ddshang/article/details/72772640
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
var http = require('http'); var moment = require('moment'); process.env.TZ = "Asia/Shanghai"; http.createServer(function (request, response) { var sql = require('mssql'); sql.close(); //连接方式1:"mssql://用户名:密码@ip地址(无需端口号)/SqlServer名/数据库名称" //连接方式2:"mssql://用户名:密码@ip地址:1433(默认端口号)/数据库名称" sql.connect("mssql://sa:s1a2@127.0.0.1/DBNAME").then(function () { new sql.Request().query('select top 10 * from TABLENAME').then(function (result) { response.writeHead(200, { "content-type": "text/html;charset=utf-8;" }); result.recordset.forEach(row => { response.write(row.ID + ' - ' + row.Name + ' - ' + moment(row.DateTime).utc().format("YYYY-MM-DD HH:mm:ss") + "<br>"); }); response.end(); }).catch(function (err) { console.log(err); }); }).catch(function (err) { console.log(err); }); }).listen(8886); |
引用: https://blog.csdn.net/u010668495/article/details/50817136 https://www.npmjs.com/package/mssql https://www.cnblogs.com/cyfhykx/p/6224078.html
View Details今天开始学习Node.js,在写一个文件上传的功能时候,调用fs.renameSync方法错误 出错代码所在如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
1 function upload(response,request){ 2 console.log("upload called"); 3 var form = new formidable.IncomingForm(); 4 console.log("about to parse"); 5 form.parse(request, function(error, fields, files) { 6 console.log("parsing done"); 7 fs.renameSync(files.upload.path, "./tmp/test.jpg"); 8 response.writeHead(200, {"Content-Type": "text/html"}); 9 response.write("received image:<br/>"); 10 response.write("<img src='/show' />"); 11 response.end(); 12 }); 13 } |
大致分析后,预计是因为跨磁盘分区移动或操作文件会有权限问题。 下面提供两种解决办法: 方法一: 主要利用fs的createReadStream、createWriteSream和unlinkSync方法 具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
1 function upload(response,request){ 2 console.log("upload called"); 3 var form = new formidable.IncomingForm(); 4 console.log("about to parse"); 5 form.parse(request, function(error, fields, files) { 6 console.log("parsing done"); 7 // fs.renameSync(files.upload.path, "./tmp/test.jpg"); 8 <strong>var readStream=fs.createReadStream(files.upload.path); 9 var writeStream=fs.createWriteStream("./tmp/test.jpg"); 10 readStream.pipe(writeStream); 11 readStream.on('end',function(){ 12 fs.unlinkSync(files.upload.path); 13 }); </strong>14 response.writeHead(200, {"Content-Type": "text/html"}); 15 response.write("received image:<br/>"); 16 response.write("<img src='/show' />"); 17 response.end(); 18 }); 19 } |
PS:我用的node版本是0.10.69,如果使用的是0.6以下的版本,可以使用util.pump 相应代码只需将上面的代码中readStream.on处改成:(注意引入util模块)
1 2 3 |
util.pump(readStream,writeStream, function() { fs.unlinkSync('files.upload.path'); }); |
方法二: 这种就简洁很多了 添加一个 form.uploadDir=’tmp' 即可(写一个临时路径)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
1 function upload(response,request){ 2 console.log("upload called"); 3 var form = new formidable.IncomingForm(); 4 <strong> form.uploadDir='tmp'; </strong> 5 6 console.log("about to parse"); 7 form.parse(request, function(error, fields, files) { 8 console.log("parsing done"); 9 fs.renameSync(files.upload.path, "./tmp/test.jpg"); 10 response.writeHead(200, {"Content-Type": "text/html"}); 11 response.write("received image:<br/>"); 12 response.write("<img src='/show' />"); 13 response.end(); 14 }); 15 } 16 |
解决问题后,就可以很开心的继续我的Node学习了,感觉路还很长啊 PS:附上两个有关Node文件上传的帖子,个人觉得挺不错的,来源都是cnode nodejs-post文件上传原理详解 node-formidable详解 from:https://www.cnblogs.com/glczero/archive/2014/08/23/3932024.html
View Details如果VS2013,在打开解决方案时,报如下错误: “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService RequiredTypeIdentity Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService 匹配的导出” 导致项目无法打开以及VS无法关闭。 解决方法: 1.关闭VS; 2.去C:/Users/<your users name>/AppData/Local/Microsoft/VisualStudio/12.0/ComponentModelCache文件夹下删除所有文件及文件夹; 3.重新打开VS即可。 如果是vs2012的话 方法一: 可以尝试删除最近更新的windows补丁更新,主要是关于.net Framework的。 如果方法一行不通,可以尝试方法二,或直接用方法二解决。 方法二: 安装微软的windows补丁 KB2781514(官网:https://www.microsoft.com/zh-cn/download/details.aspx?id=36020) ,补丁主要解决“在 .NET Framework 4.5 更新之后,Visual Studio 用户可能无法打开或创建 C++ 或 JavaScript 文件或项目。” from:https://www.cnblogs.com/ChineseMoonGod/p/5687521.html
View Details注:laravel 查询返回行的都是 php 的 stdClass 对象实例,不是数组!!!! 1)查询多行(get)
1 |
DB::table('table_name')->get(); |
带偏移和限制的查询(skip take 或 offset limit)(两种用法是一样的)
1 2 3 4 5 |
//skip take DB::table('table_name')->skip(10)->take(10)->get(); //offset limit DB::table('table_name')->offset(20)->limit(10)->get(); |
2)查询一行(first)
1 |
DB::table('table_name')->first(); |
1 |
DB::table('table_name')->find(1); |
PS:find方法也可以查多行,它可以这样玩 DB::table('table_name')->find([1,2,3,4]); 3)直接查询一个字段(value)
1 |
DB::table('table_name')->where('name','Tiac')->value('email'); |
4)查询一列(pluck)
1 |
DB::table('table_name')->where('brand_id','100')->pluck('goods_id'); |
5)块组结果集(chunk) 使用情景: 假设我们需要查询 1 百万的数据,并对其做处理,一次性查询 1 百万并统一处理势必会对数据产生不小的压力,消耗大量的服务器资源,有没有一种更做优的处理方法? 将 1 百万的查询分成 1000 次 1000 条记录的查询的块查询怎样?? 这个 chunk的作用,chunk方法接口一个闭包函数做回调处理
1 2 3 4 5 |
DB::table('users')->orderBy('id')->chunk(1000, function($users) { foreach ($users as $user) { // } }); |
PS:上面只是举例,chunk 貌似不能和 limit 一起用,chunk 默认情况下一次性处理整张表的数据,不过我可以通过自己加判断用 return false 跳出 chunk 操作 6)聚合函数(count max min avg sum 等等)
1 |
DB::table('table_name')->count(); |
PS:其他聚合函数的使用方法一样的,不一一举例了 7)where 条件字句 这个比较多,懒得写了,想看的直接到 laravel 学院看吧,传送门:http://laravelacademy.org/post/6140.html#ipt_kb_toc_6140_8 (where, orWhere, whereNUll, whereIn, whereNotIn, whereBetween, whereNotBetween, whereDate, whereYear, whereMonth, whereDay 等等) 8)orderBy 排序字句
1 |
DB::table('table_name')->orderBy('id','desc')->get(); |
PS:如果想要返回随机的查询结果集,可以使用 inRandomOrder 子句 […]
View Details
1 2 3 4 |
$user_info = DB::table('usermetas') ->select('browser', DB::raw('count(*) as total')) ->groupBy('browser') ->get(); |
from:https://stackoverflow.com/questions/18533080/laravel-eloquent-groupby-and-also-return-count-of-each-group
View Details昨天在写程序的时候,发现在用户的时候记录IP和地区信息也许以后用得上,去网上找了找,发现实现的方式有好多好多,因为我用的ThinkPHP,后来又去TP官网找了找,最后采用了下面这种方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +---------------------------------------------------------------------- // | Copyright (c) 2009 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- /** * IP 地理位置查询类 修改自 CoolCode.CN * 由于使用UTF8编码 如果使用纯真IP地址库的话 需要对返回结果进行编码转换 * @author liu21st <liu21st@gmail.com> */ class IpLocation { /** * QQWry.Dat文件指针 * * @var resource */ private $fp; /** * 第一条IP记录的偏移地址 * * @var int */ private $firstip; /** * 最后一条IP记录的偏移地址 * * @var int */ private $lastip; /** * IP记录的总条数(不包含版本信息记录) * * @var int */ private $totalip; /** * 构造函数,打开 QQWry.Dat 文件并初始化类中的信息 * * @param string $filename * @return IpLocation */ public function __construct($filename = "UTFWry.dat") { $this->fp = 0; if (($this->fp = fopen(dirname(__FILE__).'/'.$filename, 'rb')) !== false) { $this->firstip = $this->getlong(); $this->lastip = $this->getlong(); $this->totalip = ($this->lastip - $this->firstip) / 7; } } /** * 返回读取的长整型数 * * @access private * @return int */ private function getlong() { //将读取的little-endian编码的4个字节转化为长整型数 $result = unpack('Vlong', fread($this->fp, 4)); return $result['long']; } /** * 返回读取的3个字节的长整型数 * * @access private * @return int */ private function getlong3() { //将读取的little-endian编码的3个字节转化为长整型数 $result = unpack('Vlong', fread($this->fp, 3).chr(0)); return $result['long']; } /** * 返回压缩后可进行比较的IP地址 * * @access private * @param string $ip * @return string */ private function packip($ip) { // 将IP地址转化为长整型数,如果在PHP5中,IP地址错误,则返回False, // 这时intval将Flase转化为整数-1,之后压缩成big-endian编码的字符串 return pack('N', intval(ip2long($ip))); } /** * 返回读取的字符串 * * @access private * @param string $data * @return string */ private function getstring($data = "") { $char = fread($this->fp, 1); while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 $data .= $char; // 将读取的字符连接到给定字符串之后 $char = fread($this->fp, 1); } return $data; // return iconv('gb2312', 'utf-8', $data); //通用函数,不能在这转 } /** * 返回地区信息 * * @access private * @return string */ private function getarea() { $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 0: // 没有区域信息 $area = ""; break; case 1: case 2: // 标志字节为1或2,表示区域信息被重定向 fseek($this->fp, $this->getlong3()); $area = $this->getstring(); break; default: // 否则,表示区域信息没有被重定向 $area = $this->getstring($byte); break; } return $area; // return iconv('gb2312', 'utf-8', $area); //在最后统一转 } /** * 根据所给 IP 地址或域名返回所在地区信息 * * @access public * @param string $ip * @return array */ public function getlocation($ip='') { if (!$this->fp) return null; // 如果数据文件没有被正确打开,则直接返回空 if(empty($ip)) $ip = get_client_ip(); $location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址 $ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址 // 不合法的IP地址会被转化为255.255.255.255 // 对分搜索 $l = 0; // 搜索的下边界 $u = $this->totalip; // 搜索的上边界 $findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) while ($l <= $u) { // 当上边界小于下边界时,查找失败 $i = floor(($l + $u) / 2); // 计算近似中间记录 fseek($this->fp, $this->firstip + $i * 7); $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 // 以便用于比较,后面相同。 if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 $u = $i - 1; // 将搜索的上边界修改为中间记录减一 } else { fseek($this->fp, $this->getlong3()); $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 $l = $i + 1; // 将搜索的下边界修改为中间记录加一 } else { // 用户的IP在中间记录的IP范围内时 $findip = $this->firstip + $i * 7; break; // 则表示找到结果,退出循环 } } } //获取查找到的IP地理位置信息 fseek($this->fp, $findip); $location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址 $offset = $this->getlong3(); fseek($this->fp, $offset); $location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址 $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 $countryOffset = $this->getlong3(); // 重定向地址 fseek($this->fp, $countryOffset); $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 2: // 标志字节为2,表示国家信息又被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $countryOffset + 4); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } break; case 2: // 标志字节为2,表示国家信息被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $offset + 8); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } if (trim($location['country']) == 'CZ88.NET') { // CZ88.NET表示没有有效信息 $location['country'] = '未知'; } if (trim($location['area']) == 'CZ88.NET') { $location['area'] = ''; } $location['country']=iconv('gb2312', 'utf-8', $location['country']); $location['area']=iconv('gb2312', 'utf-8', $location['area']); return $location; } /** * 析构函数,用于在页面执行结束后自动关闭打开的文件。 * */ public function __destruct() { if ($this->fp) { fclose($this->fp); } $this->fp = 0; } } IpLocation.class.php |
这个是TP里带的,从上面的信息上来看已经很旧了,不过感觉写的还不错,就没改什么,只是在后面加上了
1 2 |
$location['country']=iconv('gb2312', 'utf-8', $location['country']); $location['area']=iconv('gb2312', 'utf-8', $location['area']); |
因为TP的纯真数据库已经转码了,但是很旧,似乎还是2012年的,IP这东西,那么老的东西估计很不准,于是我去纯真官网下了一个,但是纯真本身是GB2312的,所以要加上上面这两句转码一下。 然后在项目中导入了这个PHP类以后,这样去用就可以。
1 2 3 |
$ip=get_client_ip(); $ipData=new IpLocation("QQWry20140125.dat"); $ipInfo=$ipData->getlocation($ip); |
得到的结果是这样的,测试IP:218.197.147.154。
1 2 3 4 5 6 |
array (size=5) 'ip' => string '218.197.147.154' (length=15) 'beginip' => string '218.197.146.1' (length=13) 'endip' => string '218.197.147.154' (length=15) 'country' => string '湖北省武汉大学' (length=21) 'area' => string '外语自主学习中心' (length=24) |
最新版的纯真数据库去纯真官网下就可以,里面的QQWry.dat就是,用的时候也可以像我那样在后面标上版本,免得以后记不清。然后把.dat跟上面的php类放在一个目录下就OK啦。 from:https://www.cnblogs.com/fordawn/p/3538665.html
View Details微软现在所有Visual Studio相关的下载到www.visualstudio.com网站下载是非常方便的 下载地址: 下载ISO版本后,进行安装,由于10-20人的小团队,不需要SharePoint所以就安装【基本服务器】版本 点击下一步 勾选试用(请支持正版),点击下一步 由于本次主要数据库选择了阿里云的RDS,而阿里云的SQL Server只有2008 R2版本而且太贵,所以就选择安装一个Express版本 由于本次发布主要采用WebDeploy,而且以前也没使用过TFS的发布,不是很熟悉流程和原理,以后有时间再研究吧,暂时不勾选生产发布代理 选择下一步 下一步后检查配置 点击配置,然后开始安装了 安装的时候发现有在线下载SQL Server Express,难怪2015.2的安装包突然小了500多M,微软真是越来越与时俱进了啊 安装后默认端口是8080,因此需要在服务器上防火墙打开8080端口 由于本次服务是采用了域名进行访问并且使用了HTTPS,因此需要在配置中更改URL并到IIS中绑定相关域名 然后新建一个用户 新建一个项目集合 然后添加刚才的用户为管理员 这样,就可以在Visual Studio里面用刚才添加的用户连接到TFS服务器了 from:https://www.cnblogs.com/printhelloworld/p/5622186.html
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
string filePath = Server.MapPath("/test.xlsx"); FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); XSSFWorkbook workbook1 = new XSSFWorkbook(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(workbook1, 100); var first = sxssfWorkbook.CreateSheet("MySheet"); for (int i = 0; i < 1000000; i++) { var row = first.CreateRow(i); for (int j = 0; j < 11; j++) { if (i == 0) { // 首行 row.CreateCell(j).SetCellValue("column" + j); } else { // 数据 if (j == 0) { row.CreateCell(j).SetCellValue(i.ToString()); } else { row.CreateCell(j).SetCellValue(new Random().Next().ToString()); } } } } sxssfWorkbook.Write(fs); fs.Close(); fs.Dispose(); |
View Details
打开选项对话框( 工具 – >选项… ). 在左侧树中,选择 项目和解决方案 节点,然后选择 生成和运行 . 注意:如果此节点没有显示出来,请确保在对话框 显示所有设置 底部的复选框被选中. 在出现的工具/选项页中,设置 MSBuild项目生成输出的详细程度 水平 详细 (假设你是在VS2010中, 正常 将在VS2008或以上即可). 生成项目。 在生成窗口中查找关键字 ResolveAssemblyReferences,快速定位错误源。 from:https://blog.csdn.net/gaoxu529/article/details/41009089
View Details