SSH架構整合實現Java三層架構執行個體(一)

來源:互聯網
上載者:User

標籤: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三層架構執行個體(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.