The difference between redirect and forward

forward (direct request forwarding) is the transfer of control in the container. The forwarded address will not be displayed in the address bar of the client browser, and it will not change the value of Request. If you need to get it in the next page For new information, you can Request.setAttribute() to place some flags so that it can be retrieved from the next page.



 
 

r redirect (indirect request forwarding) is a complete redirect, the browser will get the redirected address and resend the request link. In this way, the link address after the jump can be seen from the address bar of the browser. Therefore, forward is more efficient. When forward can meet the needs, try to use the Request Dispatcher.forward() method, and this also helps to hide the actual link. In some cases, for example, you need to jump to a resource on another server, you must use the HttpServletResponse.sendRequest() method.



 
 

 Here is my own code:

             

/**
 * Commodity request processing class
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin/goodstype/")
public class GoodsTypeAction {
	GoodsTypeDao goodsTypeDao = null;
	/**
	 * delete item
	 * @param code
	 * @return
	 */
	@RequestMapping("/delete")
	public String deletegoodsType(int code){
		goodsTypeDao = new GoodsTypeDao();
		goodsTypeDao.deleteGoodsType(code);
		return "forward:/admin/goodstype/goodstypeList";
		
	}

	/**
	 * Update, modify and save products
	 * @param goodstype
	 * @return
	 */
	@RequestMapping("/update")
	public String updateGoodsType(GoodsType goodstype){
		goodsTypeDao = new GoodsTypeDao();
		goodsTypeDao.updateGoodsType(goodstype);
		return "redirect:/admin/goodstype/goodstypeList";
	}
}	 

-------------------------------------------------------------------------------------------------------------------------------------

public class GoodsTypeDao extends BaseDao {
	private static final String NAMESPACE_NAME = "com.carshop.mapper.GoodsTypeMapper.";
	/**
	 * Delete the specified product code
	 * @param code
	 * @return
	 */
	public int deleteGoodsType(int code){
		SqlSession session = getSqlSession();
		int count = session.delete(NAMESPACE_NAME+"deleteGoodsType",code);
		session.commit();
		closeSqlSession();
		return count;
	}
	/**
	 * Get product details by code
	 * @param code
	 * @return
	 */
	public GoodsType getGoodsTypeByCode(String code){
		SqlSession session = getSqlSession();
		GoodsType Goodstype = session.selectOne(NAMESPACE_NAME+"getGoodsTypeByCode",code);
		closeSqlSession();
		return Goodstype;
	}
	/**
	 * Update and modify the product
	 * @param code
	 * @return
	 */
	public int updateGoodsType(GoodsType goodstype){
		SqlSession session = getSqlSession();
		int count = session.update(NAMESPACE_NAME+"updateGoods",goodstype);
		session.commit();
		closeSqlSession();
		return count;
		
	}
}

-------------------------------------------------------------------------------------------------------------------------------

 

<?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.carshop.mapper.GoodsTypeMapper">
	<!-- Precompile sql statements to improve reuse -->
	<sql id="findgoodstype">
		select * from e_goods_type  
	</sql>
	
	<!-- Get item type -->
	<select id="getGoodsTypeList" resultType="goodsType">
		<include refid="findgoodstype"/>
		order by code asc
	</select>
	<!-- Delete product according to code-->
	<select id="deleteGoodsType">
		delete from e_goods_type where code = #{code}
	</select>
	<!-- Query products according to code-->
	<select id="getGoodsTypeByCode" resultMap="goodstype">
		<include refid="findgoodstype"/>
		<where>
			code = #{code}
		</where>
	</select>
	<!-- Update Modified Product-->
	<update id="updateGoods">
		update e_goods_type set name=#{name},remark=#{remark} where code=#{code}
	</update>
	
	<!-- Define ResultMap -->
	<resultMap type="GoodsType" id="goodstype" autoMapping="true">
		<!-- Define the correspondence between columns and java object properties-->
		<!-- Mapping: column is the database column name property is the definition name of dto; we often use the definition name to facilitate data acquisition -->
		<result column="code" property="code"/>
		<result column="name" property="name"/>
		<result column="remark" property="remark"/>
	</resultMap>
</mapper>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326415481&siteId=291194637