一个学生含有多个奖项,一个奖项分配给多个学生(多对多)。一对一,奖项名称通过状态表获得。
people_status:
对学生的奖项进行增加修改删除。
增加某个学生的奖项,就是在people_status表中增加一条记录 。其他同理.
sql:
<select id="getAwardList" parameterClass="youth" resultClass="com.fjxhx.business.people.model.YouthModel"> $pageBegin$ select a.id,a.name,a.identityId,a.tel,a.email,a.nation, a.projectDiscribe,a.feature,a.applyDate,a.fundedDate,a.fundedMoney,a.applyTime,a.equipDate,a.trainRecord, a.helpYear,a.teacherId, getAwardName(a.id) as youthAward, getTeacherName(a.teacherId) as teacherNameTree, o.orgName AS projectPlace, (select b.value from b_status b where b.content=a.isDisable and b.code='yn') as isDisable, (select b.value from b_status b where b.content=a.isUndergrate and b.code='yn') as isUndergrate, (select b.value from b_status b where b.content=a.sex and b.code='sex') as sex, (select b.value from b_status b where b.content=a.projectCode and b.code='project_industry') as projectCode, (select b.value from b_status b where b.content=a.hkType and b.code='hkType') as hkType, (select b.value from b_status b where b.content=a.education and b.code='youth_education') as education from ybc_youth a,ybc_org o where a.projectPlace=o.orgCode <dynamic prepend="and"> <isNotEmpty prepend="and" property="projectPlace"> projectPlace = #projectPlace# </isNotEmpty> <isNotEmpty prepend="and " property="name"> name like concat('%', #name#, '%') </isNotEmpty> <isNotEmpty prepend="and" property="tel"> tel like concat('%', #tel#, '%') </isNotEmpty> <isNotEmpty prepend="and" property="apply_beginTime" > <![CDATA[ applyDate >= #apply_beginTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="apply_endTime" > <![CDATA[ applyDate <= #apply_endTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="funded_beginTime" > <![CDATA[ fundedDate >= #funded_beginTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="funded_endTime" > <![CDATA[ fundedDate <= #funded_endTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="statusContent"> a.id in(SELECT s.peopleId FROM ybc_people_status s WHERE s.statusCode='youth_award' AND s.statusContent=#statusContent#) </isNotEmpty> </dynamic> $pageEnd$ </select> <select id="getAwardAddList" parameterClass="youth" resultClass="com.fjxhx.business.people.model.YouthModel"> $pageBegin$ select a.id,a.name,a.identityId,a.tel,a.email,a.nation, a.projectDiscribe,a.feature,a.applyDate,a.fundedDate,a.fundedMoney,a.applyTime,a.equipDate,a.trainRecord, a.helpYear,a.teacherId, getAwardName(a.id) as youthAward, getTeacherName(a.teacherId) as teacherNameTree, o.orgName AS projectPlace, (select b.value from b_status b where b.content=a.isDisable and b.code='yn') as isDisable, (select b.value from b_status b where b.content=a.isUndergrate and b.code='yn') as isUndergrate, (select b.value from b_status b where b.content=a.sex and b.code='sex') as sex, (select b.value from b_status b where b.content=a.projectCode and b.code='project_industry') as projectCode, (select b.value from b_status b where b.content=a.hkType and b.code='hkType') as hkType, (select b.value from b_status b where b.content=a.education and b.code='youth_education') as education from ybc_youth a,ybc_org o where a.projectPlace=o.orgCode <dynamic prepend="and"> <isNotEmpty prepend="and" property="projectPlace"> projectPlace = #projectPlace# </isNotEmpty> <isNotEmpty prepend="and " property="name"> name like concat('%', #name#, '%') </isNotEmpty> <isNotEmpty prepend="and" property="tel"> tel like concat('%', #tel#, '%') </isNotEmpty> <isNotEmpty prepend="and" property="apply_beginTime" > <![CDATA[ applyDate >= #apply_beginTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="apply_endTime" > <![CDATA[ applyDate <= #apply_endTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="funded_beginTime" > <![CDATA[ fundedDate >= #funded_beginTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="funded_endTime" > <![CDATA[ fundedDate <= #funded_endTime# ]]> </isNotEmpty> <isNotEmpty prepend="and" property="statusContent"> a.id not in(SELECT s.peopleId FROM ybc_people_status s WHERE s.statusCode='youth_award' AND s.statusContent=#statusContent#) </isNotEmpty> </dynamic> $pageEnd$ </select> <insert id="add_people_status" parameterClass="com.fjxhx.business.people.model.YouthModel" > insert into ybc_people_status (peopleId,statusCode,statusContent) values(#peopleId#,'youth_award',#statusContent#) </insert> <delete id="del_people_status" parameterClass="com.fjxhx.business.people.model.YouthModel"> delete from ybc_people_status where peopleId=#peopleId# and statusCode='youth_award' and statusContent=#statusContent# </delete>
java:
public void getAwardList() { model.setFisrtRow((model.getPage() - 1) * model.getRows()); model.setLastRow(model.getRows()); try { BaseDao dao = getDao(); List<YouthModel> peopleIds = dao.selectForList( "youth.getAwardList", model); HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("total", peopleIds.size()); hm.put("rows", peopleIds); hm.put("success", true); this.doResponseWithJson(hm); } catch (Exception e) { e.printStackTrace(); this.setData("操作失败"); this.setSuccess(false); this.send(); } } public void getAwardAddList() { model.setFisrtRow((model.getPage() - 1) * model.getRows()); model.setLastRow(model.getRows()); try { BaseDao dao = getDao(); List<YouthModel> peopleIds = dao.selectForList( "youth.getAwardAddList", model); HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("total", peopleIds.size()); hm.put("rows", peopleIds); hm.put("success", true); this.doResponseWithJson(hm); } catch (Exception e) { e.printStackTrace(); this.setData("操作失败"); this.setSuccess(false); this.send(); } } public void addAwardConfig() { try { BaseDao dao = getDao(); String peopleId[] = model.getPeopleId().split(","); for (int i = 0; i < peopleId.length; i++) { YouthModel temp = new YouthModel(); temp.setPeopleId(peopleId[i]); temp.setStatusContent(model.getStatusContent()); dao.insertSql("youth.add_people_status", temp); } } catch (Exception e) { e.printStackTrace(); this.setData("操作失败"); this.setSuccess(false); this.send(); } } public void removeAwardConfig() { try { BaseDao dao = getDao(); String peopleId[] = model.getPeopleId().split(","); for (int i = 0; i < peopleId.length; i++) { YouthModel temp = new YouthModel(); temp.setPeopleId(peopleId[i]); temp.setStatusContent(model.getStatusContent()); dao.insertSql("youth.del_people_status", temp); } } catch (Exception e) { e.printStackTrace(); this.setData("操作失败"); this.setSuccess(false); this.send(); } }
相关推荐
ibatis配置多表关联(一对一、一对多、多对多
本文将深入探讨如何在iBATIS中实现一对多和多对多的关系映射,并提供相关的源码分析和工具使用技巧。 **一对多关系映射** 在数据库设计中,一对多关系是指一个父记录可以与多个子记录关联,例如,一个用户可以有多...
iBatis多对多关系详解 iBatis是一种流行的持久层框架,用于简化Java应用程序...我们使用了三个数据库表来存储学生和教师之间的多对多关系,并使用iBatis来映射数据库表和Java对象。最后,我们实现了DAO来访问数据库。
总结来说,这个话题覆盖了Mybatis/iBatis中的多表映射,通过XML配置文件处理一对一和一对多关系,以及如何在ExtJS前端通过Model和Grid获取并展示这些数据。了解这些知识对于开发涉及多表交互的应用至关重要,能够...
在Ibatis中,多表查询是一项重要的功能,它允许我们处理复杂的数据库操作,例如一对多、多对一或一对一的关系。在这个例子中,我们将探讨如何使用Ibatis进行一对多的多表查询,以`book`和`user`两个表为例。 首先,...
2. **配置一对多关联** 在iBatis的映射文件中,我们需要为主表(一对一的一方)和从表(一对一的多方)分别创建`<resultMap>`。在主表的`<resultMap>`中,通过`<collection>`标签指定从表的映射信息,包括属性名、...
2. **一对多映射**:如果一个表的数据对应另一个表的多条记录,例如订单表和订单详情表,一个订单可以包含多个详情。这里,我们同样使用`<resultMap>`,但在SQL查询中使用`<collection>`标签来处理多个子记录。 3. ...
为了演示Ibatis的多表查询功能,本文档采用了一个简单的例子:一个图书 (`book`) 表和一个用户 (`user`) 表,其中图书表与用户表之间存在一对多的关系。这意味着每本书可以有多个作者。 **图书表 (`book`) 结构:** ...
本文将深入探讨如何利用Ibatis实现一对多关系、批处理、事务管理和与Spring及Struts2的集成。 首先,让我们来看一下“一对多”关系。在数据库设计中,一对多关系很常见,比如一个用户可以有多个订单。在Ibatis中,...
一对多映射是数据库关系模型中的常见概念,指的是一个父表(如部门表)可以对应多个子表(如员工表),每个部门可以有多个员工。在`iBatis` 中,我们可以利用映射文件来配置这种关系,以便在查询时自动处理关联数据...
这样,当我们调用`SqlSession`的`selectList`方法执行这个查询时,Ibatis会自动将返回的多条记录按照一对多的关系映射成`User`对象,每个`User`对象都有一个包含所有关联订单的`orderList`。 此外,还可以通过使用`...
ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南ibatis2指南
本文将深入探讨如何在iBATIS中进行主子表查询,以及涉及到的相关技术如一对多关系、日志管理库log4j等。 首先,主子表查询是数据库设计中常见的场景,通常涉及到一个“父”表(主表)和一个或多个“子”表(从表)...
在数据库设计中,多表查询通常涉及到表之间的关联,例如一对一、一对多、多对多关系。在iBatis中,我们可以使用`<select>`标签来定义多表查询的SQL语句。 ### 3. 使用`<include>`标签 为了保持SQL语句的整洁和可...
在关系型数据库中,多对多(Many-to-Many)关系是一种常见的关联类型,例如学生与课程的关系,一个学生可以选修多个课程,同时一门课程也可以被多个学生选修。在Ibatis中处理多对多关系时,我们需要使用关联映射来...
包括了几部分: ...7.iBatis2学习笔记:多对多映射(双向) .doc 8.iBatis2学习笔记:总结与思考.doc 9.iBatis2实体状态图解.doc 10.iBatis insert操作陷阱.doc 每章都有小例子。 呵呵,希望有所帮助!
Source Database : ibatis_db Target Server Type : MYSQL Target Server Version : 50022 File Encoding : 65001 Date: 2013-05-02 22:49:28 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- --...