
2009年5月3日
今天在做SSH的练习,页面传递过来id,当我用this.getHibernateTemplate().delete(user);删除数据时,总是抛出异常。
User类中有3个字段,分别是id、username、password,均为非空字段。所以在User.hbm.xml中not-null="true",结果在视图删除时,就会抛出not-null property references a null or transient value这样的异常。这是因为所有字段均为非空字段,而仅仅只给id赋值了,其余字段为空,所以抛出此异常。
解决办法,先按id查询出此对象,然后进行删除,不会出错了,不过这样效率不高,先进行了一次查询。
User user = (User) this.getHibernateTemplate().get(User.class, id);
this.getHibernateTemplate().delete(user);
posted @ 2009-05-03 18:00 清晨阳光 阅读(489) 评论(0)
编辑

2009年5月1日
没事写了个ping局域网电脑的小工具,可以获得活动主机的IP地址和MAC地址。源代码:LanScan.7z
获得MAC地址,要求TCP/IP中启用了NetBIOS,如果没有启用,将仅获得IP地址。
posted @ 2009-05-01 12:55 清晨阳光 阅读(123) 评论(0)
编辑

2009年4月21日
.Net中的RichTextBox control采用的是很古老的native Windows RichText control,它缺少支持表格元素中的\par,所以当粘贴表格进来时,如果有换行,则格式会错乱。Windows XP中的写字板对表格支持得很好,它采用了msftedit.dll。我们可以考虑自己写一个RichTextBox5,继承自System.Windows.Forms.RichTextBox,然后就可以彻底解决这个问题。代码如下:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace EasyNote
{
public class RichTextBox5 : RichTextBox
{
private static IntPtr moduleHandle;
protected override CreateParams CreateParams
{
get
{
if (moduleHandle == IntPtr.Zero)
{
moduleHandle = LoadLibrary("msftedit.dll");
if ((long)moduleHandle < 0x20)
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not load Msftedit.dll");
}
}
CreateParams createParams = base.CreateParams;
createParams.ClassName = "RichEdit50W";
if (this.Multiline)
{
if (((this.ScrollBars & RichTextBoxScrollBars.Horizontal) != RichTextBoxScrollBars.None) && !base.WordWrap)
{
createParams.Style |= 0x100000;
if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x2000;
}
}
if ((this.ScrollBars & RichTextBoxScrollBars.Vertical) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x200000;
if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x2000;
}
}
}
if ((BorderStyle.FixedSingle == base.BorderStyle) && ((createParams.Style & 0x800000) != 0))
{
createParams.Style &= -8388609;
createParams.ExStyle |= 0x200;
}
return createParams;
}
}
// P/Invoke declarations
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadLibrary(string path);
}
}
posted @ 2009-04-21 08:53 清晨阳光 阅读(598) 评论(0)
编辑

2009年4月5日
这篇文章已经沉底了,献给有缘人吧。 源代码(VS2008工程):EasyNote.7z
这是个纪念版,在关于里面加入了一些我想对她说的话。
去年的4月9日,我和女朋友一起在历史博物馆门口照相,之后去吃了黄金老碗鱼,而今年的4月9日,她即将离开,和其他人结婚了。我曾经深深地伤害过她,很对不起她。仅以此版本纪念我最心爱的她。
EasyNote is dedicated to my beloved ex-girlfriend Mary. Thank you for giving me the best days of my life! I did mistake of pushing you away, you gave me your heart but I threw it away, tossed it into the ocean. I remember we took a lot of photos at the gate of the History Museum and then had Golden Aged Bowl Fish together on April 9th of last year. I remember we climbed the mountain together, I remember we walked in the snow together, I remember we faced the 512 Wenchuan Big Earthquake together. Every detail, every moment of our happy days recurred to me day after day. Now you're going to get married with somebody else, time has passed and things have become chaotic, I really regret it. I'm so sorry for being an idiot and hurting you. Hope you can read these words, I'd do anything to make you happy if you just trust me, please forgive me.
大雪纷飞,你我沿街而行
春暖花开,你我漫步花丛
沥沥春雨,你我共撑雨伞
雪依然下,却感觉孤寂寒冷
花依然开,却感觉不再美丽
春雨又来,却感觉丝丝凄凉
公园里,你我曾欢声笑语
公园里,你我曾玩捉迷藏
公园里,你我曾跳兔子舞
如今的公园,只剩下我孤单地来回踱步
如今的公园,只剩下我孤单地仰望星空
如今的公园,只剩下我在寻找你的影子
你将离去,今生再无缘
漫漫长路我于是孤单地走
曾经无情地背叛
才有今日泪水模糊的双眼
长条状的烤红薯
多汁的甘蔗
皮薄的沙田柚
金黄的菠萝
香甜的哈密瓜
鲜嫩的黄瓜
烫手的煮玉米
可水可香可甜的水萝卜
红灿灿的灯笼柿子
如今,我已很少吃这些
幸福,自你走后再没陪伴过我
我不奢求自己过得很好
只想恳求你从心底里原谅我
同时忠心地祝福你幸福快乐
posted @ 2009-04-05 10:40 清晨阳光 阅读(540) 评论(5)
编辑

2008年10月8日
这个问题也是无意中得知的,原因在于我在模糊查询的时候输入了一个%,谁知将全部结果都查询出来了,想了一下,%既然是通配符,输了个%进去,当然全部查询出来了,避免的办法就是使用ESCAPE。
SQL语句可以写成:
SELECT * FROM tableName WHERE colName LIKE '%' + input + '%' ESCAPE '\\';
这里假设我们的输入是input,在源程序里,input需要进行处理,
input = input.Replace("'", "''"); //将1个单引号替换为2个单引号,防止SQL注入
input = input.Replace("\\", "\\\\"); //将反斜杠替换为2个反斜杠
input = input.Replace("%", "\\%");//将%替换为\%
input = input.Replace("_", "\\_"); //将_替换为\_
上面3个替换就是将原字符前面加上反斜杠,这样输入到SQL语句中,ESCAPE '\\'的作用就是将反斜杠后面的字符识别成普通字符,而不是通配符,这下在进行模糊查询,输入通配符就不会有错误了。
注意,一定要先替换反斜杠,然后再替换%和_
posted @ 2008-10-08 11:35 清晨阳光 阅读(216) 评论(1)
编辑