標籤:bsp parameter actual cat nal 完成 sse shp data-
HTML前台發送請求代碼:
1 <tr>2 <td>選擇收派時間</td>3 <td>4 <input type="text" name="takeTimeId" class="easyui-combobox" required="true"5 data-options="url:‘../../taketime_findAll.action‘, 6 valueField:‘id‘,textField:‘name‘" />7 </td>8 </tr>
TakeTimeAction代碼:
1 @Namespace("/") 2 @ParentPackage("json-default") 3 @Controller 4 @Scope("prototype") 5 public class TakeTimeAction2 extends BaseAction<TakeTime> { 6 @Autowired 7 private TakeTimeService2 takeTimeService; 8 @Action(value="taketime_findAll",results={@Result(name="success",type="json")}) 9 public String findAll(){10 //調用業務層,查詢所有收派時間11 List<TakeTime> taketime = takeTimeService.findAll();12 //壓入值棧返回13 ActionContext.getContext().getValueStack().push(taketime);14 return SUCCESS;15 }16 }
抽取的Action公用類BaseAction代碼:
1 public abstract class BaseAction<T> extends ActionSupport implements 2 ModelDriven<T> { 3 // 模型驅動 4 protected T model; 5 @Override 6 public T getModel() { 7 return model; 8 } 9 // 構造器 完成model執行個體化10 public BaseAction() {11 // 構造子類Action對象 ,擷取繼承父類型的泛型12 // AreaAction extends BaseAction<Area>13 // BaseAction<Area>14 Type genericSuperclass = this.getClass().getGenericSuperclass();15 // 擷取類型第一個泛型參數16 ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;17 Class<T> modelClass = (Class<T>) parameterizedType18 .getActualTypeArguments()[0];19 try {20 model = modelClass.newInstance();21 } catch (InstantiationException | IllegalAccessException e) {22 e.printStackTrace();23 System.out.println("模型構造失敗...");24 }25 }26 // 接收分頁查詢參數27 protected int page;28 protected int rows;29 public void setPage(int page) {30 this.page = page;31 }32 public void setRows(int rows) {33 this.rows = rows;34 }35 // 將分頁查詢結果資料,壓入值棧的方法36 protected void pushPageDataToValueStack(Page<T> pageData) {37 Map<String, Object> result = new HashMap<String, Object>();38 result.put("total", pageData.getTotalElements());39 result.put("rows", pageData.getContent());40 ActionContext.getContext().getValueStack().push(result);41 }42 }
收派時間介面TakeTimeService代碼:
1 public interface TakeTimeService2 {2 //查詢所有收派時間3 List<TakeTime> findAll();4 }
收派介面實作類別TakeTimeServiceImpl代碼:
1 @Service 2 @Transactional 3 public class TakeTimeServiceImpl2 implements TakeTimeService2 { 4 @Autowired 5 private TakeTimeRepository2 takeTimeRepository; 6 @Override 7 public List<TakeTime> findAll() { 8 return takeTimeRepository.findAll(); 9 }10 }
dao層TakeTimeRepository代碼:
1 public interface TakeTimeRepository2 extends JpaRepository<TakeTime, Integer> {}
SSH架構整合實現Java三層架構執行個體(一)