📄 userbean.java
字号:
package com.accp;
import java.sql.*;
import java.util.*;
import javax.faces.context.*;
import javax.faces.model.*;
import javax.servlet.jsp.jstl.sql.*;
public class UserBean {
private String chapterdetail = "";
private String chaptermaster = "";
private String chapter = "";
private String id;
private String age;
public Collection getAlll()
{
Collection coll = new ArrayList();
String sql = "select * from chapter";
BaseDao db = new BaseDao();
try {
ResultSet rs = db.executeQuery(sql);
while (rs.next()) {
ChapterForm form = new ChapterForm();
form.setId(rs.getString(1));
form.setChapter(rs.getString(2));
form.setChapterdetail(rs.getString(3));
form.setChaptermaster(rs.getString(4));
coll.add(form);
}
}
catch (Exception ex) {
System.out.println(ex);
}
finally {
db.close();
}
return coll;
}
public Result getAll()
{
String sql = "select * from chapter";
BaseDao db = new BaseDao();
try {
ResultSet rs = db.executeQuery(sql);
return ResultSupport.toResult(rs);
}
catch (SQLException ex) {
}finally
{
db.close();
}
return null;
}
public String add()
{
String sql = "insert into chapter(chapter,chapterdetail,chaptermaster) values('"+this.getChapter()+"','"+this.getChapterdetail()+"','"+this.getChaptermaster()+"')";
BaseDao db = new BaseDao();
try {
db.executeUpdate(sql);
}
catch (SQLException ex) {
}finally
{
db.close();
}
return "list";
}
public String show()
{
FacesContext ctx = FacesContext.getCurrentInstance();
String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
String sql = "select * from chapter where ID="+ID;
BaseDao db = new BaseDao();
try {
ResultSet rs = db.executeQuery(sql);
if(rs.next())
{
this.setId(rs.getString(1));
this.setChapter(rs.getString(2));
this.setChapterdetail(rs.getString(3));
this.setChaptermaster(rs.getString(4));
System.out.println(this.getId());
}
}
catch (SQLException ex) {
}finally
{
db.close();
}
return "update";
}
public String update()
{
System.out.println(this.getId());
String sql = "update chapter set chapter = '"+this.getChapter()+"',chapterdetail='"+this.getChapterdetail()+"',chaptermaster='"+this.getChaptermaster()+ "' where ID="+this.getId();
BaseDao db = new BaseDao();
try {
db.executeUpdate(sql);
}
catch (SQLException ex) {
}finally
{
db.close();
}
return "list";
}
public String delete()
{
FacesContext ctx = FacesContext.getCurrentInstance();
String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
String sql = "delete from chapter where ID="+ID;
BaseDao db = new BaseDao();
try {
db.executeUpdate(sql);
}
catch (SQLException ex) {
}finally
{
db.close();
}
return "list";
}
public UserBean() {
}
public void setChapterdetail(String chapterdetail) {
this.chapterdetail = chapterdetail;
}
public void setChaptermaster(String chaptermaster) {
this.chaptermaster = chaptermaster;
}
public void setChapter(String chapter) {
this.chapter = chapter;
}
public void setId(String id) {
this.id = id;
}
public void setAge(String age) {
this.age = age;
}
public String getChapterdetail() {
return chapterdetail;
}
public String getChaptermaster() {
return chaptermaster;
}
public String getChapter() {
return chapter;
}
public String getId() {
return id;
}
public String getAge() {
return age;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -