예제 #1
0
 public static Object getSupplierList() {
   CommonDao commonDao = (CommonDao) ApplicationContextBean.getBean("commonDao");
   String sql = "select * from t_supplier";
   Map<String, NullableType> scalars = new HashMap<String, NullableType>();
   Object object = commonDao.querySqlToList(sql, scalars, 0, 10, new Object[] {});
   return object;
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 public static JSONObject saveOrUpdate(String id, String name, String phoneNumber) {
   JSONObject json = new JSONObject();
   Integer intId = (id == null) ? 0 : Integer.parseInt(id);
   CommonDao commonDao = (CommonDao) ApplicationContextBean.getBean("commonDao");
   /**
    * 有待评估是否需要 existCustomer = getCustomerById(commonDao, intId); if(null == existCustomer){
    * json.put("status", "failed"); json.put("code", "CT_001"); return json; }
    */
   Supplier entity = null;
   // 0是新增,否则是更新
   if (intId == 0) {
     entity = new Supplier(name, phoneNumber);
   } else {
     entity = new Supplier(intId, name, phoneNumber);
   }
   try {
     commonDao.getHibernateTemplate().saveOrUpdate(entity);
   } catch (DataAccessException e) {
     log.error("saveOrUpdate Supplier failed!", e);
     json.put("status", "failed");
     json.put("code", "CT_002");
     return json;
   }
   json.put("status", "success");
   json.put("code", "CT_003");
   return json;
 }
예제 #3
0
 public static Customer getCustomerById(CommonDao commonDao, Integer id) {
   if (null == id || id == 0) {
     return null;
   }
   return commonDao.getHibernateTemplate().get(Customer.class, id);
 }