今天的东西有点稍微多,我也不知道能不能整理完
不过打字是给我累坏了
来回跳窗口是真的麻烦
我们就不能恩恩爱爱的一个方法一个方法写么兄弟
1
先说昨天遇到的二笔错误
c3po配置文件,是要放在src下的
蠢。
然后我想写一下C3P0Utils
pubic class C3P0Utils
{
private static DataSource ds = new ComboPooledDataSource();
public static DataSource getDataSource()
{
return ds;
}
}
再写两边!
private static DataSource ds = new CooboPooledDataSource();
private static DataSource ds= new CooboPooledDataSource();
2
几个数据库查询方法,我还是不太熟练
单个查询:
return qr.query(“select * from table where name=?”,
new BeanHander<User>(User.class),user.getname);
新增:
return qr.update(“insert into table(属性,属性) values(?,?),user.get属性)
修改:
return qr.update(“update table set 属性=?,属性=?”,user.get属性);
删除
return qr.update(“delete from table where useId=?”,userId);
模糊查询
这个方法确实挺好玩啊
可以再写一遍
public List<User> find(User u)
{
if(StringUtils.isBlank(u.getName)&&StringUtils.isBlank(u.getPassword))
{
return findAll();
}
else
{
String sql=”select * from table where 1=1”;
List<Object> list = new ArrayList<Object>();
if(StringUtils.isBlank(u.getName()))
{
sql+=” and userName like ?”;
list.add(u.getName);
}
if(StringUtils.isBlank(u.getPassword))
{
sql+=” and userPassword like ?”;
}
return qr.query(sql,new BeanListHander<User>(User.class),list.toArray());
}
return null;
}
果然没写完。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
接着写吧 昨天写到哪了啊明显是忘记了啊,我想一想想一想刚写完dao方法
还剩三个 Action,xml,和JSP
JSP太无聊了 ,先等一等
写一下 xml吧
大方向差不多了,主要是细节问题。
XML
1
<constant name=”struts.devMode” value=”true”></constant>
这个是改了不用重启,虽然我发现他并没有什么软用
<constant name=”struts.ognl.allowStaticMethodAccess” value=”true”></constant>
见名知义啊同学们见名知义
允许静态方法调用 ===》通道打开,权限开放,嘟嘟嘟
虽然我忘了怎么用的了,一会写到再回来看吧。
2
重定向
比如增加完要返回界面刷新啊,就可以用这个直接跳到方法
让我们找一找,能不能自己写出来呢
不能
好吧
嘿,找到了,处理文件的太恶心了等我单独写
其实很简单啊,
<result type=”redirectAction” name=”success”>findAll</result>
redirectAction redirectAction redirectAction redirectAction
redirectAction redirectAction redirectAction redirectAction
redirectAction redirectAction redirectAction redirectAction
剩下都好容易啊,,还是写文件吧
敲黑板:关于文件的上传和下载(第n次重复)
先从JSP写起来
enctype=”multipart/form-data”
(对了命名空间这个命名在包上)
这个file有点出乎意料啊,,,
<s:file name=”upload” size=”30”></s:file>
然后应该写action的
但是我就是不想写,太麻烦了,而且我都写过好几回了也不会
也不是不会吧就是没有深入搞懂
直接写到xml里面
上传
<interceptor-ref name=”defaultStack”>
<param name=”fileUpload.allowedExtensions”>dox</param>
</interceptor-ref>
这个是设置类型的 不设置的也行
写一个下载,下载还是比较好玩的
<result type=”stream”>这个是type哦
<param name=”inputName”>inputStream</param>这个inputStream就是流
<param name="contentType">application/octet-stream</param>
<param name="contentDisposition">attachment;filename=${@java.net.URLEncoder@encode(oldFileName,"utf-8")}</param>