mms项目

1.controller

1.1.AdminController

@Controller("adminController")
public class AdminController{
    
    @Autowired
    private AdminService adminService;
    
    @RequestMapping("/index")
    public String index() {
        return "forward:selectAll.do";
    }
    
    @RequestMapping("/login")
    public String login() {
        return "login";
    }
    
    @PostMapping("login.do")
    public String login(HttpServletRequest request,HttpSession session,Admin admin){
        admin.setPwd(new MD5Code().getMD5ofStr(admin.getPwd()));
        session.setAttribute("admin", admin);
        Admin admin2=adminService.selectByusernameAndPwd(admin);
        long currentTimeMillis = System.currentTimeMillis();
        admin=adminService.selectByusername(admin.getName());
        if(admin!=null) {
            if(admin.getState()==0) {
                if(currentTimeMillis-Long.parseLong(admin.getLasttime())>=24*60*60*1000) {
                    admin.setWrongtimes(0);
                    admin.setState(1);
                    adminService.updateAdmin(admin);
                }else {
                    request.setAttribute("loginError", "登录失败超过5次!您的账号被锁定,请24小时后登录");
                    System.out.println("五次");
                    return "login";
                }
            }
        }
        if(admin2!=null) {
            admin2.setLasttime(currentTimeMillis+"");
            System.out.println("登录成功");
            admin2.setWrongtimes(0);
            adminService.updateAdmin(admin2);
            System.out.println("设置输入错误次数为零"+admin2);
            session.setAttribute("admin", admin2);
            return "redirect:selectAll.do";
        }else {
            System.out.println("用户名密码错误");
//            admin=adminService.selectByusername(admin.getName());
            if(admin!=null) {
                String currentTimeMillis_str=""+currentTimeMillis;
                admin.setLasttime(currentTimeMillis_str);
                System.out.println(currentTimeMillis_str);
                System.out.println("有此用户名");
                if(currentTimeMillis-Long.parseLong(admin.getLasttime())>=24*60*60*1000) {
                    admin.setWrongtimes(0);
                }else {
                    admin.setWrongtimes(admin.getWrongtimes()+1);
                    if(admin.getWrongtimes()>=5) {
                        admin.setState(0);
                    }
                    adminService.updateAdmin(admin);
                }
                //剩余次数
                int leavetimes=5-admin.getWrongtimes();
                request.setAttribute("loginError", "登录失败,用户名或密码错误,您还有"+leavetimes+"机会");
                return "login";
            }else {
                System.out.println("无此用户名");
                request.setAttribute("loginError", "该用户不存在");
                return "login";
            }
        }
    }
    
    @RequestMapping("/logout.do")
    public String logout(HttpServletRequest request,HttpSession session,Admin admin) {
        session.removeAttribute("admin");
        System.out.println("已注销");
        return "login";
    }
    
    @RequestMapping("/addAdmin")
    public String addAdmin(HttpSession session) {
        //验证是否是超级管理员
        Admin admin=(Admin) session.getAttribute("admin");
        if(admin.getRole()==0) {
            return "addAdmin";
        }else {
            return "forward:selectAll.do";
        }
        
    }
    
    @RequestMapping("/addAdmin.do")
    public String addAdmin(Admin admin) {
        adminService.insert(admin);
        return "redirect:showAdmin.do";
    }
    
    @RequestMapping("/showAdmin.do")
    public String showAdmin(Model model,HttpSession session) {
        //验证是否是超级管理员
        Admin admin=(Admin) session.getAttribute("admin");
        if(admin.getRole()!=0) {
            return "forward:selectAll.do";
        }
        List<Admin> adminList = adminService.selectAll();
        System.out.println(adminList);
        model.addAttribute("adminList", adminList);
        return "showAdmin";
    }
    @RequestMapping("/updateAdmin")
    public String updateAdmin(int id,Model model) {
        Admin admin = adminService.selectById(id);
        model.addAttribute("admin", admin);
        return "updateAdmin";
    }     
    @RequestMapping("/updateAdmin.do")
    public String updateAdmin(Admin admin) {
        System.out.println(admin);
        System.out.println("修改用户信息");
        admin.setPwd(new MD5Code().getMD5ofStr(admin.getPwd()));
        adminService.updateAdmin(admin);
        return "forward:showAdmin.do";
    }
    
    @RequestMapping("/deleteAdmin.do")
    public String deleteAdmin(int id) {
        adminService.deleteAdminById(id);
        return "forward:showAdmin.do";
    }
    
    
    
    
    
//    @RequestMapping("/login")
//    public ModelAndView login(Admin admin) throws Exception{
//        ModelAndView mv = new ModelAndView();
//        Admin a = adminService.selectByusernameAndPwd(admin);
////        List<Admin> list=adminService.
//        //根据用户名和密码查询user,如果存在,则跳转到 success.jsp 页面
//        if(a != null){
//            mv.addObject("name", a.getName());
//            mv.addObject("user", a);
//            mv.setViewName("/index.jsp");
//        }else{
//            //如果不存在,则跳转到 login.jsp页面重新登录
//            return new ModelAndView("redirect:/login.jsp");
//        }
//        return mv;
//    }
    
    
    
    
    
}
View Code

 

1.2.BigTypeController

@Controller
public class BigTypeController {
    
    @Autowired
    private BigTypeService bigTypeService;
    
    
    
    @RequestMapping("/addBigType")
    public String addBigType() {
        return "addBigType";
    }
    
    @RequestMapping("/addBigType.do")
    public String addBigType(BigType bigType) {
        bigTypeService.insert(bigType);
        return "showPro";
    }
    
    
}
View Code

 

1.3.InputController

@Controller
public class InputController {
    
    @Autowired
    private InputService inputService;
    @Autowired
    private ProductsService productsService;
    @Autowired
    private ProviderService providerService;
    
    @RequestMapping("/inputProducts")
    public String inputProducts(Input input,Products products,Model model) {
        Date date=new Date();
        input.setInputtime(date);
        //插入库存记录
        System.out.println(input);
        inputService.insert(input);
        //更新products表
        products.setCreatetime(date);
        products.setName(input.getName());
        if (input.getPcount()>0) {
            products.setCount(products.getCount()+input.getPcount());
            productsService.updateProducts(products);
            //将数据返回页面
            List<Input> ilist = inputService.selectAll();
            System.out.println(ilist);
            model.addAttribute("ilist", ilist);
            return "forward:searchInput";
        }else {
            String message="入库失败";
            model.addAttribute("input_error", message);
            return "selectAll.do";
        }
    }
    
    @RequestMapping("/searchInput")
    public String SearchInput(Model model) {
        List<Input> ilist = inputService.selectAll();
        List<Provider> proList=providerService.selectAll();
        System.out.println("searchInput"+ilist+"/n"+proList);
        model.addAttribute("proList", proList);
        model.addAttribute("ilist", ilist);
        return "searchInput";
    }
    
    @RequestMapping("/searchInputByKeyword.do")
    public <T> String SearchInput(HttpServletRequest request,
            String name,String annt,String pname,
            @DateTimeFormat(pattern="yyyy-mm-dd")Date startDate,
            @DateTimeFormat(pattern="yyyy-mm-dd")Date enDate,Model model) 
    {
        Map map=new HashMap();
        map.put("name", name);
        map.put("pname", pname);
        map.put("annt", annt);
        map.put("startDate",request.getParameter("startDate"));
        map.put("enDate",request.getParameter("enDate"));
//        System.out.println("ttttttttttttttt"+map);
        List<Input> ilist = inputService.selectByKeyword(map);
//        System.out.println(ilist);
        List<Provider> proList=providerService.selectAll();
        model.addAttribute("proList", proList);
        model.addAttribute("ilist", ilist);
        return "searchInput";
    }
    
    
    @RequestMapping("groupByInputResult.do")
    public String  selectByGroupName(Model model) {
        List<Input> ilist = inputService.selectByGroupName();
        int countTotal=0;
        BigDecimal priceTotal = new BigDecimal(0);
        for (Input input : ilist) {
            countTotal+=input.getPcount();
            priceTotal=priceTotal.add(input.getPrice());
            System.out.println(input.getPrice());
            System.out.println(priceTotal);
            System.out.println("------------------------------------------------------------------------");
        }
        model.addAttribute("countTotal", countTotal);
        model.addAttribute("priceTotal", priceTotal);
        model.addAttribute("ilist", ilist);
        return "groupByInputResult";
    }
}
View Code

 

1.4.OutputController

@Controller
public class OutputController {
    
    @Autowired
    private OutputService outputService;
    @Autowired
    private ProductsService productsService;
    
    
    
    @RequestMapping("/outputProducts")
    public String outputProducts(Output output,Products products) {
        Date date=new Date();
        output.setOutputtime(date);
        outputService.insert(output);
        products.setName(output.getName());
        products.setCreatetime(date);
        products.setCount(products.getCount()-output.getPcount());
        productsService.updateProducts(products);
        return "forward:selectAll.do";
    }
    
    @RequestMapping("/searchOutput")
    public String SearchOutput(Model model) {
        List<Output> olist = outputService.selectAll();
        System.out.println(olist);
        model.addAttribute("olist", olist);
        return "searchOutput";
    }
    
    @RequestMapping("/searchOutputByKeyword.do")
    public <T> String SearchOutput(HttpServletRequest request, String name,String annt,
            @DateTimeFormat(pattern="yyyy-mm-dd")Date startDate,
            @DateTimeFormat(pattern="yyyy-mm-dd")Date enDate,Model model) 
    {
        System.out.println("123123123");
        Map map=new HashMap();
        map.put("name", name);
        map.put("annt",annt);
        map.put("startDate",request.getParameter("startDate"));
        map.put("enDate",request.getParameter("enDate"));
        System.out.println("321321223");
        System.out.println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"+map);
        List<Output> olist=outputService.selectByKeyword(map);
        System.out.println("olist--------------"+olist);
        model.addAttribute("olist", olist);
        return "searchOutput";
    }
    
    @RequestMapping("groupByOutputResult.do")
    public String groupByOutputResult(Model model) {
        int countTotal=0;
        List<Output> olist = outputService.selectByGroupName();
        for (Output output : olist) {
            countTotal+=output.getPcount();
        }
        model.addAttribute("countTotal", countTotal);
        model.addAttribute("olist", olist);
        return "groupByOutputResult";
    }
}
View Code

 

1.5.ProductsController

@Controller
public class ProductsController {
    
    @Autowired
    private ProductsService productsService;
    
    private PageUtils pageUtils=new PageUtils();
    @Autowired
    private ProviderService providerService;
    
    
    @RequestMapping("/selectAll.do")
    public String selectAll(Model model,Integer cp,HttpSession session) {
        System.out.println("cp:"+cp);
        if(cp==null) {
            pageUtils.setCurrentPage(1);
        }else {
            pageUtils.setCurrentPage(cp);
        }
        //给分页组件设置内容
        pageUtils.setPageSize(20);
        pageUtils.setTotal(productsService.selectCount());
        //设置zongyes
        int pageTotal=pageUtils.getTotal()%pageUtils.getPageSize()==0?pageUtils.getTotal()/pageUtils.getPageSize():
            (pageUtils.getTotal()/pageUtils.getPageSize()+1);
        pageUtils.setPageTotal(pageTotal);
        List<Products> list = productsService.selectAll(
                new RowBounds((pageUtils.getCurrentPage()-1)*pageUtils.getPageSize(),
                        pageUtils.getPageSize()));
        List<BigType> bigList=productsService.selectBigType();
        List<BigType> smallList=productsService.selectSmallType();
        System.out.println("bigType--------------"+bigList);
        System.out.println("smallType--------------"+smallList);
        session.setAttribute("bigList", bigList);
        session.setAttribute("smallList", smallList);
        System.out.println(pageUtils);
        if(list==null) {
            model.addAttribute("msg","数据加载不到请重试");
        }else {
            model.addAttribute("p", pageUtils);
            model.addAttribute("pList",list);
            model.addAttribute("URL","selectAll.do");
        }
        return "index";
    }
    
    @RequestMapping("/selectByName.do")
    public <T> String findProByNameAndType(String keyword,Integer sid,Model model) {
        Map<String, T> map=new HashMap<>();
        map.put("keyword", (T) keyword);
        map.put("sid",(T) sid);
        System.out.println("ssssssssssssssssss"+map);
        List<Products> products=productsService.selectByNameAndType(map);
        model.addAttribute("pList",products);
        return "searchResult";
    }
    
    @RequestMapping("/inputPro.do")
    public String inputPro(String keyword,Model model) {
        List<Products> products=productsService.selectByName(keyword);
        model.addAttribute("pList",products);
        return "searchResult";
    }    
    
    @RequestMapping("/FindProByIdServlet")
    public String findProById(int id,int flag,Model model) {
        Products product=productsService.selectById(id);
        model.addAttribute("p",product);
        if(flag==1) {
            List<Provider> proList=providerService.selectAll();
            model.addAttribute("proList", proList);
            return "input";
        }else if(flag==2){
            return "output";
        }else if(flag==3) {
            return "showPro";
        }else {
            return "forward:selectAll.do";
        }
    }
    
    @RequestMapping("/newProduct")
    public String newProduct() {
        return "newInput";
    }
    @RequestMapping("/newProduct.do")
    public String newProduct(Products products) {
        System.out.println(products);
        productsService.insertProduct(products);
        return "forward:selectAll.do";
    }
    
    
    @RequestMapping("/updateProducts")
    public String updateProducts() {
        return "showPro";
    }
    
    @RequestMapping("/updateProducts.do")
    public String updateProducts(Products products) {
        productsService.updateProducts(products);
        return "forward:selectAll.do";
    }
    
    @RequestMapping("/outputData.do")
    public void outputData(HttpServletResponse response) {
        List<Products> proList=productsService.selectAll();
        ExportExcel<Products> ee=new ExportExcel<Products>();
        String[] Pheaders = {"id","name","bid","sid","units","count","wvalue","state","createtime"};
        String PfileName="productExcel";
        ee.exportExcel(Pheaders, proList, PfileName, response);

    }
    
    
}
View Code

 

1.6.ProviderController

@Controller
public class ProviderController {
    
    @Autowired
    private ProviderService providerService;
    
    @RequestMapping("/addProvider")
    public String addProvider() {
        return "addGys";
    }
    
    @RequestMapping("/addProvider.do")
    public String addProvider(Provider provider) {
        providerService.insert(provider);
        return "redirect:selectAll.do";
    }
}
View Code

 

1.7.SmallTypeController

@Controller
public class SmallTypeController {
    
    @Autowired
    private SmallTypeService smallTypeService;
    @Autowired
    private ProductsService productsService;
    
    @RequestMapping("/addSmallType")
    public String addsmallType() {
        return "addSmallType";
    }
    
    @RequestMapping("/addSmallType.do")
    public String addsmallType(SmallType smallType) {
        smallType.setState(1);
        System.out.println(smallType);
        smallTypeService.insert(smallType);
        return "newInput";
    }
    
    @RequestMapping("/selectSmallByBid.do")
    public void selectSmallByBid(Integer bid ,HttpServletResponse response ) throws IOException {
        JSONArray jsonArray=new JSONArray();
        System.out.println(productsService.selectSmallTypeByBigType(bid));
        List<SmallType> smallList = productsService.selectSmallTypeByBigType(bid);
        System.out.println(smallList);
        for(SmallType smallType:smallList) {
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("sid", smallType.getId());
            jsonObject.put("sname", smallType.getName());
            jsonArray.add(jsonObject);
        }
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonArray.toString());
    }
}
View Code

 

 

2.interceptor

2.1.LoginInterceptor

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
        // TODO Auto-generated method stub

    }

    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {

        // 1.定义哪些路径是不需要拦截(将这些路径称为白名单)
        Set<String> uri = new HashSet<String>();
//        uri.add("/logout.do");
        uri.add("/login.do");
        uri.add("/login");
        // 获取请求路径.
        String servletPath = request.getServletPath();
        System.out.println(123);
        if (uri.contains(servletPath)) {
            return true;
        }

        // 2.判断用户是否登录,如果登录就放行
        HttpSession session = request.getSession();
        Admin admin = (Admin) session.getAttribute("admin");// Const.LOGIN_USER
        if (admin != null) {
            System.out.println("未拦截");
            return true;
        } else {
            System.out.println("拦截");
            System.out.println(request.getContextPath());
             response.sendRedirect(request.getContextPath()+"/login"); 
//            request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
            return false;
        }
    }
}
View Code

 

3.mapper

3.1.AdminMapper

public interface AdminMapper {
    long count();

    int deleteByName(String name);

    int insert(Admin admin);

    List<Admin> selectAll();

    int updateAdmin(Admin admin);

    Admin selectByusernameAndPwd(Admin admin);

    Admin selectByusername(String name);

    void deleteById(int id);

    Admin selectById(int id);
}
View Code

 

3.2.AdminMapper.xml

<?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.ssm.mapper.AdminMapper">
  
  
 <update id="updateAdmin" parameterType="com.ssm.pojo.Admin">
    update t_admin
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="pwd != null">
        pwd = #{pwd,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        state = #{state,jdbcType=INTEGER},
      </if>
      <if test="wrongtimes != null">
        wrongtimes = #{wrongtimes,jdbcType=INTEGER},
      </if>
      <if test="lasttime != null">
        lasttime = #{lasttime,jdbcType=VARCHAR},
      </if>
      <if test="role != null">
        role = #{role,jdbcType=VARCHAR},
      </if>
      
    </set>
    where name=#{name}
  </update>
  
  <select id="selectByusernameAndPwd" parameterType="com.ssm.pojo.Admin" resultType="com.ssm.pojo.Admin">
    select * from t_admin where name=#{name} and pwd=#{pwd}
  </select>
  
  <select id="selectByusername" parameterType="String" resultType="com.ssm.pojo.Admin">
    select * from t_admin where name=#{name}
  </select>
  
  <select id="selectById" parameterType="Integer" resultType="com.ssm.pojo.Admin">
    select * from t_admin where id=#{id}
  </select>
  
  <select id="selectAll"  resultType="com.ssm.pojo.Admin">
    select * from t_admin
  </select>
  
  <insert id="insert" parameterType="com.ssm.pojo.Admin" >
      insert into t_admin(name,pwd,role) values(#{name},#{pwd},#{role})
  </insert>
  
  <delete id="deleteByName" parameterType="String">
      delete from t_admin where name=#{name}
  </delete>
  
  <delete id="deleteById" parameterType="Integer">
      delete from t_admin where id=#{id}
  </delete>
  
  
</mapper>
View Code

 

3.3.BigTypeMapper

public interface BigTypeMapper {
    long countByExample(BigTypeExample example);

    int deleteByExample(BigTypeExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(BigType record);

    int insertSelective(BigType record);

    List<BigType> selectByExample(BigTypeExample example);

    BigType selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") BigType record, @Param("example") BigTypeExample example);

    int updateByExample(@Param("record") BigType record, @Param("example") BigTypeExample example);

    int updateByPrimaryKeySelective(BigType record);

    int updateByPrimaryKey(BigType record);
}
View Code

 

3.4.BigTypeMapper.xml

<?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.ssm.mapper.BigTypeMapper">
  <resultMap id="BaseResultMap" type="com.ssm.pojo.BigType">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="state" jdbcType="INTEGER" property="state" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, name, state
  </sql>
  <select id="selectByExample" parameterType="com.ssm.pojo.BigTypeExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_bigtype
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_bigtype
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_bigtype
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.ssm.pojo.BigTypeExample">
    delete from t_bigtype
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.ssm.pojo.BigType">
    insert into t_bigtype (id, name, state
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.ssm.pojo.BigType">
    insert into t_bigtype
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="state != null">
        state,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        #{state,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.ssm.pojo.BigTypeExample" resultType="java.lang.Long">
    select count(*) from t_bigtype
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update t_bigtype
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.state != null">
        state = #{record.state,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update t_bigtype
    set id = #{record.id,jdbcType=INTEGER},
      name = #{record.name,jdbcType=VARCHAR},
      state = #{record.state,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.ssm.pojo.BigType">
    update t_bigtype
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        state = #{state,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ssm.pojo.BigType">
    update t_bigtype
    set name = #{name,jdbcType=VARCHAR},
      state = #{state,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
View Code

 

 

4.pojo

 

5.service

5.1.AdminService

public interface AdminService {

    Admin selectByusernameAndPwd(Admin admin);
    int insert(Admin admin);
    Admin selectByusername(String name);
    void updateAdmin(Admin admin);
    List<Admin> selectAll();
    void deleteAdmin(String name);
    void deleteAdminById(int id);
    Admin selectById(int id);
}
View Code

 

5.2.AdminServiceImpl

@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService{
    
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin selectByusernameAndPwd(Admin admin){
        return adminMapper.selectByusernameAndPwd(admin);
    }
    @Override
    public int insert(Admin admin) {
        
        return adminMapper.insert(admin);
    }
    @Override
    public Admin selectByusername(String name) {
        return adminMapper.selectByusername(name);
    }
    @Override
    public void updateAdmin(Admin admin) {
        adminMapper.updateAdmin(admin);
    }
    @Override
    public List<Admin> selectAll() {
        return adminMapper.selectAll();
    }
    @Override
    public void deleteAdmin(String name) {
        adminMapper.deleteByName(name);
        
    }
    @Override
    public void deleteAdminById(int id) {
        adminMapper.deleteById(id);
        
    }
    @Override
    public Admin selectById(int id) {
        // TODO Auto-generated method stub
        return adminMapper.selectById(id);
    }
    
}
View Code

 

 

6.util

6.1.PageUtils

public class PageUtils {
    public PageUtils(){
        System.out.println("qqqqqqqqqqq");
    }
    private int pageTotal;//总页数
    private int pageSize;//每页显示的记录条数
    private int currentPage;//当前页
    private int total;//总记录数
    
    public int getPageTotal() {
        return pageTotal;
    }
    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    @Override
    public String toString() {
        return "PageUtils [pageTotal=" + pageTotal + ", pageSize=" + pageSize + ", currentPage=" + currentPage
                + ", total=" + total + "]";
    }
    
    
    
}
View Code

 

 

7.配置

7.1.jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/kucun
jdbc.username=kucun
jdbc.password=root
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
View Code

 

7.2.mybatis-config.xml

<?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>    
 <typeAliases>
           <package name="com.ssm.pojo"/>
   </typeAliases>
    
</configuration>
View Code

 

7.3.spring.xml

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
         <!--读取db.properties -->
    <context:property-placeholder location="classpath:config/jdbc.properties"/>
    
    <context:component-scan base-package="com.ssm" />
        
   <!--  <context:exclude-filter type="annotation" expression="com.ssm.controller.AdminController"/> -->
    <!-- 配置数据源 -->    
    <bean id="dataSource" 
            class="org.apache.commons.dbcp2.BasicDataSource">
        <!--数据库驱动 -->
        <property name="driverClassName" value="${jdbc.driver}" />
        <!--连接数据库的url -->
        <property name="url" value="${jdbc.url}" />
        <!--连接数据库的用户名 -->
        <property name="username" value="${jdbc.username}" />
        <!--连接数据库的密码 -->
        <property name="password" value="${jdbc.password}" />
        <!--最大连接数 -->
        <property name="maxTotal" value="${jdbc.maxTotal}" />
        <!--最大空闲连接  -->
        <property name="maxIdle" value="${jdbc.maxIdle}" />
        <!--初始化连接数  -->
        <property name="initialSize" value="${jdbc.initialSize}" />
    </bean>
    <!-- <bean name="admin" class="com.ssm.pojo.Admin"></bean>
    <bean name="adminService" class="com.ssm.service.AdminServiceImpl"></bean> -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 扫描的包路径,如果需要扫描多个包,中间使用逗号分隔 -->
        <property name="basePackage" value="com.ssm.mapper"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!--配置MyBatis工厂 -->  
    <bean id="sqlSessionFactory" 
            class="org.mybatis.spring.SqlSessionFactoryBean">
             <!--注入数据源 -->
         <property name="dataSource" ref="dataSource" />
         <!--指定核心配置文件位置 -->
           <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
   </bean>
   
</beans>
View Code

 

7.4.springmvc-config.xml

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd   
        http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd   
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-4.3.xsd   
        http://www.springframework.org/schema/aop   
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd   
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd ">


    <context:component-scan base-package="com.ssm.controller" />
    <mvc:annotation-driven />


    <mvc:resources mapping="/js/**" location="/js/"/>  
    <mvc:resources mapping="/images/**" location="/static_resources/images/"/>
     
    <!--声明拦截器对象-->
    <mvc:interceptors>
        <bean
            class="com.ssm.interceptor.LoginInterceptor" />
        <mvc:interceptor>
            <mvc:mapping path="/*/*" />
            <!--  <mvc:exclude-mapping path="/login.do" /> 
              <mvc:exclude-mapping path="/js/**"/> -->
            <bean
                class="com.ssm.interceptor.LoginInterceptor" />
        </mvc:interceptor>
        
    </mvc:interceptors>  
    
    
    

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>
View Code

 

7.5.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>mms</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/spring.xml</param-value>
  </context-param>
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc/springmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
View Code

 

posted @ 2019-07-11 12:13  惯看秋风  阅读(14)  评论(0)    收藏  举报