<select id="findByName" resultType="com.xujunfei.entity.UserInfo">
时间: 2023-12-05 07:19:32 浏览: 123
这是 MyBatis 中的一个 SQL 映射文件的 XML 标签,用于定义一个查询语句。其中,id 属性指定了这个查询语句的名称,resultType 属性指定了查询结果集的映射类型。在这个例子中,查询语句的名称是 findByName,查询结果集的映射类型是 com.xujunfei.entity.UserInfo。
相关问题
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.teacher_admin_system.mappers.EvaluationMapper"> <resultMap id="EvaluationResult" type="com.example.teacher_admin_system.pojo.Evaluation"> <!--<result column="id" property="id"></result> <result column="teacher_id" property="teacher_id"></result> <result column="evaluator_name" property="evaluator_name"></result> <result column="content" property="content"></result> <result column="score" property="score"></result> <result column="time" property="time"></result>--> <result column="name" property="name"></result> <result column="avg(score)" property="avg"></result> </resultMap> <select id="findAll" resultMap="EvaluationResult"> select name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id group BY teacher_id </select> <select id="findById" resultMap="EvaluationResult"> select teacher.name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id group BY teacher_id HAVING teacher_id = #{id};</select> <select id="findByName" resultMap="EvaluationResult"> select teacher.name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id join department on department.id=teacher.department_id where department.name='???????' group BY teacher_id; </select> </mapper>
这是一个 MyBatis 的 Mapper 文件,它定义了一个名为 "com.example.teacher_admin_system.mappers.EvaluationMapper" 的命名空间,其中包含三个 SQL 查询语句。第一个查询语句是 "findAll",它使用了一个 "EvaluationResult" 的结果映射,从 "evaluation" 和 "teacher" 两个表中联合查询并计算平均分数,最终以教师名字和平均分数作为结果返回。第二个查询语句是 "findById",它也使用了 "EvaluationResult" 的结果映射,从 "evaluation" 和 "teacher" 两个表中联合查询并计算指定教师的平均分数,最终以教师名字和平均分数作为结果返回。第三个查询语句是 "findByName",它也使用了 "EvaluationResult" 的结果映射,从 "evaluation"、"teacher" 和 "department" 三个表中联合查询并计算指定部门中所有教师的平均分数,最终以教师名字和平均分数作为结果返回。需要注意的是,该文件中的部分内容被省略或用 "???" 替代,需要根据实际情况进行填写。
@RequestMapping(value="/list") public String list(Goods goods,PageBean<Goods> pageBean,Model model){ if(goods.getStudent() != null && goods.getStudent().getSn() != null){ Student student = studentService.findBySn(goods.getStudent().getSn()); if(student != null){ goods.setStudent(student); } } if(goods.getGoodsCategory() != null && goods.getGoodsCategory().getName() != null){ List<GoodsCategory> goodsCategorys = goodsCategoryService.findByName(goods.getGoodsCategory().getName()); if(goodsCategorys != null && goodsCategorys.size() > 0){ goods.setGoodsCategory(goodsCategorys.get(0)); } }讲解一下
这是一个Spring MVC的Controller中的一个方法,该方法处理一个名为"/list"的请求。该方法接受三个参数:Goods对象、PageBean<Goods>对象和Model对象。
其中,Goods是一个实体类,用于封装商品信息,PageBean用于封装分页信息,Model用于向前端传递数据。
在方法中,首先判断传入的Goods对象中是否有学生信息,并根据学生编号查询学生,如果学生存在,则将学生信息封装到Goods对象中。接着,判断Goods对象中是否有商品分类信息,并根据商品分类名称查询商品分类,如果商品分类存在,则将商品分类信息封装到Goods对象中。
最后,该方法将封装好的Goods对象和PageBean对象作为参数传递给业务层,查询符合条件的商品信息,并将查询结果封装到PageBean对象中。最后,将PageBean对象和其他需要在前端展示的数据封装到Model对象中,返回视图名。
阅读全文
相关推荐
















