投影查询指的是:单击下拉框,显示数据库中数据字典表已有的数据类型名称,无重复的遍历到下拉菜单中,如图所示
1.在ElecSystemDDLAction的home添加:public class ElecSystemDDLAction extends BaseAction
{ ElecSystemDDL elecSystemDDL=this.getModel(); //注入数据字典service@Resource(name=IElecSystemDDLService.SERVICE_NAME) IElecSystemDDLService elecSystemDDLService; /** * @Name: home * @Description: 跳转到数据字典页面 * @Parameters: 无 * @Return: String:跳转到system/dictionaryIndex.jsp*/public String home(){// 1:查询数据库中已有的数据类型,返回List集合 List list=elecSystemDDLService.findSystemDDLListByDistinct();// 2:将ElecSystemDDL对象放入request中 request.setAttribute("list", list);return "home"; }}2.在IElecSystemDDLService中声明投影查询方法:public interface IElecSystemDDLService {public static final String SERVICE_NAME="cn.elec.service.impl.ElecSystemDDLServiceImpl"; List findSystemDDLListByDistinct(); }3.在ElecSystemDDLServiceImpl中进行重写:public class ElecSystemDDLServiceImpl implements IElecSystemDDLService{//数据字典Dao@Resource(name=IElecSystemDDLDao.SERVICE_NAME)private IElecSystemDDLDao elecSystemDDLDao; /** * @Name: findSystemDDLListByDistinct * @Description: 查询数据库中已有的数据类型,去掉重复值 * @Parameters: 无 * @Return: List:存储数据类型集合*/@Override @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,readOnly=false)public List findSystemDDLListByDistinct() { List list=elecSystemDDLDao.findSystemDDLListByDistinct();return list; }}4.在IElecSystemDDLDao中声明投影查询方法:public interface IElecSystemDDLDao extends ICommonDao {public static final String SERVICE_NAME="cn.elec.dao.imp.ElecSystemDDLImpl"; List findSystemDDLListByDistinct();}5.在ElecSystemDDLImpl中重写该方法:@Repository(IElecSystemDDLDao.SERVICE_NAME)public class ElecSystemDDLImpl extends ICommonDaoImpl implements IElecSystemDDLDao{/** * @Name: findSystemDDLListByDistinct * @Description: 查询数据库中已有的数据类型,去掉重复值 * @Parameters: 无 * @Return: List:存储数据类型集合*/@Overridepublic List findSystemDDLListByDistinct() {//返回List集合List systemList = new ArrayList();/**方法一:投影查询一个字段返回List