1、生日:回显的格式不对,需要格式化
2、推荐人身份证号
--需要回显。即需要根据表中的推荐人ID,查询出该推荐人的身份证。
--推荐人可以修改,修改之后需要查询出对应的ID并赋值给hidden,将hidden的值提交给
recommenderId属性。
3、有两个请求
请求1,打开修改页面
请求2,提交保存
代码:
--DAO
--Action
--struts.xml
--JSP
Action:
struts.xml
Jsp:
2、推荐人身份证号
--需要回显。即需要根据表中的推荐人ID,查询出该推荐人的身份证。
--推荐人可以修改,修改之后需要查询出对应的ID并赋值给hidden,将hidden的值提交给
recommenderId属性。
3、有两个请求
请求1,打开修改页面
请求2,提交保存
代码:
--DAO
--Action
--struts.xml
--JSP
DAO:
public Account findById(Integer id) throws DAOException {
if(id==null){
return null;
}
String sql = "select * from account where id=?";
Connection con = DBUtil.getConnection();
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setObject(1, id);
ResultSet rs = ps.executeQuery();
if(rs.next()){
Account a = createAccount(rs);
if(a.getRecommenderId()!=null){
String sql2 = "select idcard_no from account where id=?";
PreparedStatement ps2 = con.prepareStatement(sql2);
ps2.setObject(1, a.getRecommenderId());
ResultSet rs2 = ps2.executeQuery();
if(rs2.next()){
String idcardNo = rs2.getString(1);
a.setRecommenderIdcardNo(idcardNo);
}
}
return a;
}
} catch (SQLException e) {
e.printStackTrace();
throw new DAOException("根据ID查询账务账号失败", e);
} finally{
DBUtil.close();
}
return null;
}
public void update(Account account) throws DAOException {
if(account==null){
return;
}
String sql = "update account set real_name=?, telephone=?, recommender_id=?, email=?, "+
"occupation=?, gender=?, mailaddress=?,zipcode=?,qq=? where id=?";
Connection con = DBUtil.getConnection();
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setObject(1, account.getRealName());
ps.setObject(2, account.getTelephone());
ps.setObject(3, account.getRecommenderId());
ps.setObject(4, account.getEmail());
ps.setObject(5, account.getOccupation());
ps.setObject(6, account.getGender());
ps.setObject(7, account.getMailaddress());
ps.setObject(8, account.getZipcode());
ps.setObject(9, account.getQq());
ps.setObject(10, account.getId());
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw new DAOException("修改账务账号失败", e);
} finally{
DBUtil.close();
}
}
Action:
public class ToUpdateAccountAction {
public String execute(){
IAccountDAO dao = DAOFactory.getAccountDAO();
try {
account = dao.findById(id);
} catch (DAOException e) {
e.printStackTrace();
return "error";
}
return "success";
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
//input
private Integer id;
//output
private Account account;
}
public class UpdateAccountAction {
public String execute(){
IAccountDAO dao = DAOFactory.getAccountDAO();
try {
dao.update(account);
} catch (DAOException e) {
e.printStackTrace();
return "error";
}
return "success";
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
//input
private Account account;
}
struts.xml
<!-- 打开修改页面 Action-->
<action name="toUpdateAccount" class="netctoss.action.account.ToUpdateAccountAction">
<result name="success">
/WEB-INF/account/updateAccount.jsp
</result>
</action>
<!-- 修改Action -->
<action name="updateAccount" class="netctoss.action.account.UpdateAccountAction">
<result name="success" type="redirectAction">
findAccount
</result>
</action>
Jsp:
function checkRecommender(){
$("#recommenderId").val("");
var recommenderIdcardNo = $("#recommenderIdcardNo").val();
if(recommenderIdcardNo==""){
$("#recommenderIdcardNoMsg").text("推荐人身份证可用").removeClass("error_msg");
return;
}
var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
if(!recommenderIdcardNo.match(reg)){
$("#recommenderIdcardNoMsg").text("推荐人身份证格式不正确").addClass("error_msg");
return;
}else{
$("#recommenderIdcardNoMsg").text("推荐人身份证可用").removeClass("error_msg");
}
$.post(
"findRecommender",
{"idcardNo":recommenderIdcardNo},
function(data){
var account = data;
alert("rec:"+account.recommenderId);
if(account.id == account.recommenderId){
$("#recommenderIdcardNoMsg").text("推荐人不能是自己").addClass("error_msg");
return;
}
if(account==null){
$("#recommenderIdcardNoMsg").text("推荐人找不到").addClass("error_msg");
}else{
$("#recommenderId").val(account.id);
$("#recommenderIdcardNoMsg").text("推荐人身份证有效").removeClass("error_msg");
}
}
);
}