验证中...
语言: Java
分类: 编程语言基础
最后更新于 2018-06-14 19:33
片段 1 片段 2 片段 3 片段 4 片段 5 片段 6 片段 7
GoodsControl
原始数据 复制代码
package com.gsdxsys.control;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.gsdxsys.entity.Goods;
import com.gsdxsys.entity.GoodsType;
import com.gsdxsys.service.GoodsService;
import com.gsdxsys.service.GoodsTypeService;
@Controller
public class GoodsControl {
@Autowired
private GoodsTypeService service;
@Autowired
private GoodsService goodsService;
@RequestMapping("/admin/goods/toadd.do")
public String toadd(HttpServletRequest request) {
List<GoodsType> types= service.getAll();
request.setAttribute("types", types);
return "admin/goods_toadd";
}
@RequestMapping("/admin/goods/doadd.do")
public String doadd(PrintWriter out,Goods goods) {
int result= goodsService.addGoods(goods);
if(result>0){
return "redirect:/admin/goods/list.do";
}else{
out.println("添加失败");
return null;
}
}
@RequestMapping("/admin/goods/list.do")
public String list(HttpServletRequest req) {
List<Goods> goods= goodsService.getAll();
req.setAttribute("goods", goods);
return "admin/goods_list";
}
}
hellocontrol
原始数据 复制代码
package com.gsdxsys.control;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloControl {
@RequestMapping("/hello.do")
public ModelAndView hello(){
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("hello");
modelAndView.addObject("message","hello spring mvc");
return modelAndView;
}
}
configuration
原始数据 复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="config/GoodsMapper.xml"/>
<mapper resource="config/GoodsTypeMapper.xml"/>
</mappers>
</configuration>
goodsmapper
原始数据 复制代码
<?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="GoodsMapper">
<select id="selectAll" resultType="com.gsdxsys.entity.Goods">
SELECT * FROM goods order by id desc
</select>
<insert id="inserGoods" parameterType="com.gsdxsys.entity.Goods">
insert into goods(goods_name,goods_price,goods_desc,typeid)
values(#{goods_name},#{goods_price},#{goods_desc},#{goodstype.id})
</insert>
</mapper>
springmvc
原始数据 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.gsdxsys.control"></context:component-scan>
<!--
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>
-->
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
spring
原始数据 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.gsdxsys">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>
userinfomapper
原始数据 复制代码
<?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="UserinfoMapper">
<select id="selectAll" resultType="com.gsdx.entity.Userinfo">
SELECT * FROM userinfo
</select>
<select id="selectByUsername" parameterType="string" resultType="com.gsdx.entity.Userinfo">
SELECT * FROM userinfo where username=#{_parameter}
</select>
<insert id="insertUser" parameterType="com.gsdx.entity.Userinfo">
insert into userinfo(username,password,realname)
values(#{username},#{password},#{realname})
</insert>
<update id="updateUser" parameterType="com.gsdx.entity.Userinfo">
update userinfo set password=#{password},realname=#{realname} where userid=#{userid}
</update>
<delete id="deleteUser" parameterType="int">
delete from userinfo where userid=#{_parameter}
</delete>
</mapper>

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助