设为首页 加入收藏

TOP

实现按条件查询(二)
2015-07-24 11:35:33 来源: 作者: 【 】 浏览:6
Tags:实现 条件 查询
,调用Service,指定查询条件查询对应的结果,返回List*/ @Test public void findCollectionByConditionNoPage(){ ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); IElecTextService elecTextService = (IElecTextService) ac.getBean(IElecTextService.SERVICE_NAME); ElecText elecText = new ElecText(); // elecText.setTextName("张"); // elecText.setTextRemark("张"); List list = elecTextService.findCollectionByConditionNoPage(elecText); if(list!=null && list.size()>0){ for(ElecText elecText2:list){ System.out.println(elecText2.getTextName()+" "+elecText2.getTextDate()+" "+elecText2.getTextRemark()); } } }


真正的action:

package com.itheima.elec.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.elec.domain.ElecSystemDDL;
import com.itheima.elec.service.IElecSystemDDLService;


@SuppressWarnings("serial")
@Controller("elecSystemDDLAction")
@Scope(value="prototype")
public class ElecSystemDDLAction extends BaseAction{
	
	ElecSystemDDL  elecSystemDDL = this.getModel();
	
	@Resource(name=IElecSystemDDLService.SERVICE_NAME)
	private IElecSystemDDLService elecSystemDDLService;
	public String home(){
		List list = elecSystemDDLService.findKeywordWithDistinct();
		request.setAttribute("list", list);
		return "home";
	}
	
	
	public String edit(){
		//获取数据类型
		String keyword = elecSystemDDL.getKeyword();
		//1:使用数据类型作为查询条件,查询数据字典表,返回List
		List list = elecSystemDDLService.findSystemDDLListByKeyword(keyword);
		request.setAttribute("systemList", list);
		return "edit";
	}
	
}
总结:根据什么样的条件查询,是在service层完成的,把所有的条件组织好后,给dao层,dao层再拼接SQL或者hql语句,进行真正的查询。web层的action只是传递参数,进行简单的调用service层的方法。?
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇【MongoDB】Mongodb数据库之Cappe.. 下一篇学生表sid,sname,成绩表cid,cname..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)