日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

SSH框架整合实现Java三层架构实例(一)

發布時間:2025/1/21 java 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SSH框架整合实现Java三层架构实例(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HTML前臺發送請求代碼:

<tr><td>選擇收派時間</td><td><input type="text" name="takeTimeId" class="easyui-combobox" required="true"data-options="url:'../../taketime_findAll.action', valueField:'id',textField:'name'" /></td> </tr>

TakeTimeAction代碼:

@Namespace("/") @ParentPackage("json-default") @Controller @Scope("prototype") public class TakeTimeAction2 extends BaseAction<TakeTime> {@Autowiredprivate TakeTimeService2 takeTimeService;@Action(value="taketime_findAll",results={@Result(name="success",type="json")})public String findAll(){//調用業務層,查詢所有收派時間List<TakeTime> taketime = takeTimeService.findAll();//壓入值棧返回ActionContext.getContext().getValueStack().push(taketime);return SUCCESS;} }

抽取的Action公共類BaseAction代碼:

public abstract class BaseAction<T> extends ActionSupport implementsModelDriven<T> {// 模型驅動protected T model;@Overridepublic T getModel() {return model;}// 構造器 完成model實例化public BaseAction() {// 構造子類Action對象 ,獲取繼承父類型的泛型// AreaAction extends BaseAction<Area>// BaseAction<Area>Type genericSuperclass = this.getClass().getGenericSuperclass();// 獲取類型第一個泛型參數ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;Class<T> modelClass = (Class<T>) parameterizedType.getActualTypeArguments()[0];try {model = modelClass.newInstance();} catch (InstantiationException | IllegalAccessException e) {e.printStackTrace();System.out.println("模型構造失敗...");}}// 接收分頁查詢參數protected int page;protected int rows;public void setPage(int page) {this.page = page;}public void setRows(int rows) {this.rows = rows;}// 將分頁查詢結果數據,壓入值棧的方法protected void pushPageDataToValueStack(Page<T> pageData) {Map<String, Object> result = new HashMap<String, Object>();result.put("total", pageData.getTotalElements());result.put("rows", pageData.getContent());ActionContext.getContext().getValueStack().push(result);} }

收派時間接口TakeTimeService代碼:

public interface TakeTimeService2 {//查詢所有收派時間List<TakeTime> findAll(); }

收派接口實現類TakeTimeServiceImpl代碼:

@Service @Transactional public class TakeTimeServiceImpl2 implements TakeTimeService2 {@Autowiredprivate TakeTimeRepository2 takeTimeRepository;@Overridepublic List<TakeTime> findAll() {return takeTimeRepository.findAll();} }

dao層TakeTimeRepository代碼:

public interface TakeTimeRepository2 extends JpaRepository<TakeTime, Integer> {}

總結

以上是生活随笔為你收集整理的SSH框架整合实现Java三层架构实例(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。