首页 技术 正文
技术 2022年11月11日
0 收藏 663 点赞 4,284 浏览 2121 个字

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> {
@Autowired
private 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 implements
ModelDriven<T> {
// 模型驱动
protected T model;
@Override
public 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 {
@Autowired
private TakeTimeRepository2 takeTimeRepository;
@Override
public List<TakeTime> findAll() {
return takeTimeRepository.findAll();
}
}

dao层TakeTimeRepository代码:

 public interface TakeTimeRepository2 extends JpaRepository<TakeTime, Integer> {}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,484
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,899
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,732
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,485
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,125
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,285