Jsp&Servlet入门级项目全程实录第6讲
2024-10-15 07:48:31
惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧!
1、建立数据表及数据(略) 2、创建student model
package com.java1234.model; import java.sql.Date; public class Student { private int id;
private String stuNo;
private String stuName;
private String sex;
private Date birthday;
private int gradeId;
private String email;
private String stuDesc; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStuNo() {
return stuNo;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public int getGradeId() {
return gradeId;
}
public void setGradeId(int gradeId) {
this.gradeId = gradeId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getStuDesc() {
return stuDesc;
}
public void setStuDesc(String stuDesc) {
this.stuDesc = stuDesc;
} } 3、查询dao
public ResultSet studentList(Connection con,PageBean pageBean)throws Exception{
StringBuffer sb=new StringBuffer("select * from t_student s,t_grade g where s.gradeId=g.id");
if(pageBean!=null){
sb.append(" limit "+pageBean.getStart()+","+pageBean.getRows());
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
} public int studentCount(Connection con)throws Exception{
StringBuffer sb=new StringBuffer("select count(*) as total from t_student s,t_grade g where s.gradeId=g.id");
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt("total");
}else{
return 0;
}
} 4、日期报错
public static String formatDate(Date date,String format){
String result="";
SimpleDateFormat sdf=new SimpleDateFormat(format);
if(date!=null){
result=sdf.format(date);
}
return result;
} if(o instanceof Date){
mapOfColValues.put(md.getColumnName(i),DateUtil.formatDate((Date)o, "yyyy-MM-dd"));
}else{
mapOfColValues.put(md.getColumnName(i),rs.getObject(i));
} 5、查询表单
<div>
学号: <input type="text" name="s_stuNo" id="s_stuNo" size="10" />
姓名: <input type="text" name="s_stuNo" id="s_stuNo" size="10" />
性别: <select class="easyui-combobox" id="s_sex" name="s_sex" editable="false" panelHeight="auto" >
<option value="" >请选择</option>
<option value="男" >男</option>
<option value="女" >女</option>
</select>
出生日期: <input type="text" class="easyui-datebox" name="s_bbirthday" id="s_bbirthday" size="11" editable="false" />->
<input type="text" class="easyui-datebox" name="s_ebirthday" id="s_ebirthday" size="11" editable="false" />
所属班级: <input class="easyui-combobox" id="s_gradeId" name="s_gradeId" size="11" data-options="editable:false,valueField:'id',textField:'gradeName',url:'gradeComboList'" />
<a href="javascript:searchStudent()" class="easyui-linkbutton" iconCls="icon-search" plain="true" >搜索</a>
</div> 6、ComboList
Connection con=null;
try {
con=dbUtil.getCon();
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("id", "");
jsonObject.put("gradeName", "请选择");
jsonArray.add(jsonObject);
jsonArray.addAll(JsonUtil.formatRsToJsonArray(gradeDao.gradeList(con, null,null)));
ResponseUtil.write(response, jsonArray);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
最新文章
- hadoop常用的操作命令
- Html5 杂记
- mysql: see all open connections to a given database?
- 如何去除My97 DatePicker控件上右键弹出官网的链接 - 如何debug混淆过的代码
- iphone删除自动更新的系统
- html5---webworker多线程
- Rules
- C++类訪问控制及继承
- Code First 数据注释--DatabaseGenerated
- 全局获取Context的技巧
- 【前端,干货】react and redux教程学习实践(二)。
- CentOS 7 服务器配置--安装Mysql
- [转载] su和sudo
- 如何在ubuntu中安装php
- Webapi创建和使用 以及填坑(三)
- bzoj2086: [Poi2010]Blocks DP,单调栈
- 使用C#读取网站相对路径文件夹下所有图片
- 菜鸟如何使用hanlp做分词的过程记录
- java中原生的发送http请求(无任何的jar包导入)
- Mac下显示和隐藏隐藏文件的命令