国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

EasyUI框架 使用Ajax提交注冊信息的實現代碼

2024-05-06 15:26:10
字體:
來源:轉載
供稿:網友

EasyUI框架 使用Ajax提交注冊信息的實現代碼

一、服務器代碼:

@Controller@Scope("prototype")public class StudentAction extends BaseAction<Student> {  private static final long serialVersionUID = -2612140283476148779L;  private Logger logger = Logger.getLogger(StudentAction.class);  private String rows;// 每頁顯示的記錄數  private String page;// 當前第幾頁  private Map<String, Object> josnMap = new HashMap<>();  // 查詢出所有學生信息  public String list() throws Exception {    return "list";  }  public String regUI() throws Exception {    return "regUI";  }  // 查詢出所有學生信息  public String listContent() throws Exception {    List<Student> list = studentService.getStudentList(page, rows);    System.out.println("list==" + list);    toBeJson(list, studentService.getStudentTotal());    return "toJson";  }  // 轉化為Json格式  public void toBeJson(List<Student> list, int total) throws Exception {    josnMap.put("total", total);    josnMap.put("rows", list);    JSONParser.writeJson(josnMap);// 自定義的工具類  }  public String reg(){    logger.error("kkk");    try {      studentService.save(model);      josnMap.put("success", true);      josnMap.put("msg", "注冊成功!");    } catch (Exception e) {      e.printStackTrace();      josnMap.put("success", false);      josnMap.put("msg", "注冊失敗!");    }    try {      ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");      ServletActionContext.getResponse().setCharacterEncoding("utf-8");      ServletActionContext.getResponse().getWriter().print(JSON.toJSONString(josnMap));    } catch (IOException e) {      e.printStackTrace();    }    return "toJson";  }  public void setRows(String rows) {    this.rows = rows;  }  public void setPage(String page) {    this.page = page;  }  public Map<String, Object> getJosnMap() {    return josnMap;  }  public void setJosnMap(Map<String, Object> josnMap) {    this.josnMap = josnMap;  }}

二、BaseAction代碼:

import java.lang.reflect.ParameterizedType;import javax.annotation.Resource;import org.apache.struts2.ServletActionContext;import cn.oppo.oa.service.DepartmentService;import cn.oppo.oa.service.ForumService;import cn.oppo.oa.service.PrivilegeService;import cn.oppo.oa.service.RoleService;import cn.oppo.oa.service.StudentService;import cn.oppo.oa.service.UserService;import com.alibaba.fastjson.JSON;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {  /**   *    */  private static final long serialVersionUID = 1L;  @Resource  protected RoleService roleService;  @Resource  protected DepartmentService departmentService;  @Resource  protected UserService userService;  @Resource  protected PrivilegeService privilegeService;  @Resource  protected ForumService forumService;  @Resource  protected StudentService studentService;  protected T model;  @SuppressWarnings("unchecked")  public BaseAction() {    try {      // 得到model的類型信息      ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();      Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];      // 通過反射生成model的實例      model = (T) clazz.newInstance();    } catch (Exception e) {      throw new RuntimeException(e);    }  }  public void writeJson(Object object){    try {      String json = JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss");      ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");      ServletActionContext.getResponse().setCharacterEncoding("utf-8");      ServletActionContext.getResponse().getWriter().write(json);      ServletActionContext.getResponse().getWriter().flush();      ServletActionContext.getResponse().getWriter().close();    } catch (Exception e) {      e.printStackTrace();    }  }  public T getModel() {    return model;  }}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 沙雅县| 罗田县| 禹城市| 庆阳市| 万州区| 泸溪县| 扎囊县| 福州市| 丹寨县| 莲花县| 那曲县| 鄂温| 怀集县| 三穗县| 昌平区| 库车县| 龙南县| 永州市| 邵东县| 鹿邑县| 肥乡县| 合川市| 石渠县| 修武县| 阿瓦提县| 蓬安县| 阿坝| 买车| 阜平县| 西青区| 兴安盟| 万年县| 上饶县| 历史| 来凤县| 池州市| 随州市| 古丈县| 柳州市| 平潭县| 调兵山市|