Layui+SSM数据表格操作(增删改查)2.0

在批量删除方法delsOrder中,foreach的collection,item属性要和jsp前端页面传入的id参数一致,#{oids}也是如此。,因为批量删除获取的id不止单个,所以使用list[]接收jsp页面参数,查询所有方法中的page和limit是页码和条数,是用来进行分页功能的。状态在数据库中是1和2,但显示在页面中是正常和加急,所以需要用到templet模板进行判断,如果有需要可以改变颜色为绿色和红色。添加表单和编辑表单中的下拉框是需要从数据库中获取的,是动态的不能写死。
摘要由CSDN通过智能技术生成

这次把批量删除写上了,也完善了非空判断

这是添加页面,物资名称下拉框是动态的! 

 

 

 这是Dao层,因为批量删除获取的id不止单个,所以使用list[]接收jsp页面参数,查询所有方法中的page和limit是页码和条数,是用来进行分页功能的。

public interface t_orderDao {
	
//	查询所有
	public List<t_order> findall(@Param("page")Integer page,@Param("limit")Integer limit,@Param("material")String material,@Param("type")Integer type);
	
//	根据物资名称和状态查询
	public Integer findbywz(@Param("material")String material,@Param("type")Integer type);

//	新增
	public Integer add(t_order tt);
	
//	修改
	public Integer update(t_order tt);
	
//	删除(修改)
	public Integer delete(Integer oid);

//	查询物资
	public List<t_material> wuz();
	
//	批量删除
	public Integer delsOrder(@Param("oids")Integer[] oids);
}

这是Mapper.xml,实现Dao层的方法。这次数据库中是有两张表,查询所有的sql语句是两表联查。在Dao层方法中添加@Param注解后就不需要在<select><insert><update><delete>元素中添加parameterType属性。

在批量删除方法delsOrder中,foreach的collection,item属性要和jsp前端页面传入的id参数一致,#{oids}也是如此。

<if test="material != null and material!=''">这里的material不是数据库中的字段,要和前端输入框中的name名一致
           

<mapper namespace="com.yzd.dao.t_orderDao">
  	<!-- 查询所有 -->
  	<select id="findall" resultType="com.yzd.entity.t_order">
		
		select t_order.oid,t_material.mid,t_material.material,t_order.num,t_order.ordertime,t_order.type,t_order.remark,t_order.delete_flag
		from t_material inner join t_order on t_material.mid=t_order.mid

		<where>
		    <if test="material != null and material!=''">
			and `material` like concat('%',#{material},'%') 
			</if>
			<if test="type != null and type!=''">
			and `type` = #{type}
			</if>
		</where>
		and t_order.delete_flag=0
		order by oid
		limit #{page},#{limit} 
  	</select>

  	<!-- 查询物资和状态 -->
  	<select id="findbywz" resultType="Integer">
  		<!-- select t_order.oid,t_material.material,t_order.num,t_order.ordertime,t_order.type,t_order.remark
		from t_material,t_order 
		where t_material.mid=t_order.mid and t_material.material like '%'${material}'%' and t_order.type=#{type}
  		 -->
  		 
  		 select count(*) from t_material,t_order 
		<where>
		    t_material.mid=t_order.mid
		    <if test="material != null and material!=''">
			and `material` like concat('%',#{material},'%') 
			</if>
			<if test="type != null and type!=''">
			and `type` = #{type}
			</if>
		</where>
		and delete_flag=0
  	</select>

  	<!-- 添加 -->
  	<insert id="add" parameterType="com.yzd.entity.t_order">
  		insert into t_order(mid,num,ordertime,type,remark,delete_flag) 
		values(#{mid},#{num},now(),#{type},#{remark},default)
  	</insert>
  	
	<!-- 修改 -->
  	<update id="update" parameterType="com.yzd.entity.t_order">
  	
  		update t_order set num=#{num},ordertime=now(),type=#{type},remark=#{remark}  where oid=#{oid}
  		
  	</update>
  	
  	<!-- 删除 -->
  	<update id="delete" parameterType="com.yzd.entity.t_order">
  		update t_order set delete_flag=1 where oid=#{oid}
  	</update>
  	
  	<!-- 查询物资 -->
  	<select id="wuz" resultType="com.yzd.entity.t_material">
  		select * from t_material
  	</select>
  	
  	<!-- 批量删除 -->
  	<update id="delsOrder">
  		update t_order set delete_flag=1 where oid in
  	<foreach collection="oids" item="oids" separator="," open="(" close=")">
  		#{oids}
  	</foreach>
  </update>
  	
</mapper>

这是Service层,和Dao层类似。

public interface t_orderService {
	
//	查询所有
	public List<t_order> findall(Integer page,Integer limit,String material,Integer type);

//	根据物资名称和状态查询
	public Integer findbywz(String material,Integer type);	

// 	添加
	public Integer add(t_order tt);
	
//	修改
	public Integer update(t_order tt);

//	删除
	public Integer delete(Integer oid);

//	查询物资
	public List<t_material> wuz();
	
//	批量删除
	Integer delsOrder(Integer[] oids);
}

这是ServiceImpl实现层,@Service和@Autowired注解不能忘记写!这个也没什么可以讲的,就是调用Dao层,实现Dao接口中的方法


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值