• Java基础入门day65


    day65

    web项目

    页面设计

    仿照小米官网,将首页保存到本地为一个html页面,再将html页面保存为jsp页面,在项目中的web.xml文件中配置了欢迎页

    
     TypesServlet
    
    package com.saas.servlet;
    ​
    import com.saas.entity.Types;
    import com.saas.service.ITypesService;
    import com.saas.service.impl.TypesServiceImpl;
    ​
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.util.List;
    ​
    @WebServlet("/TypesServlet")
    public class TypesServlet extends HttpServlet {
    ​
     private ITypesService typesService = new TypesServiceImpl();
    ​
     @Override
     protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         List types = typesService.getAllTypes();
    ​
         req.setAttribute("types", types);
    ​
         req.getRequestDispatcher("types.jsp").forward(req, resp);
     }
    }
    package com.saas.service;
    ​
    import com.saas.entity.Types;
    ​
    import java.util.List;
    ​
    public interface ITypesService {
     List getAllTypes();
    }
    package com.saas.service.impl;
    ​
    import com.saas.dao.ITypesDao;
    import com.saas.dao.impl.TypesDaoImpl;
    import com.saas.entity.Types;
    import com.saas.service.ITypesService;
    ​
    import java.util.List;
    ​
    public class TypesServiceImpl implements ITypesService {
    ​
     private ITypesDao typesDao = new TypesDaoImpl();
    ​
     @Override
     public List getAllTypes() {
         return typesDao.getAllTypes();
     }
    }
    package com.saas.dao;
    ​
    import com.saas.entity.Types;
    ​
    import java.util.List;
    ​
    public interface ITypesDao {
     List getAllTypes();
    }
    package com.saas.dao.impl;
    ​
    import com.saas.dao.ITypesDao;
    import com.saas.entity.Types;
    import com.saas.util.DruidUtil;
    import org.apache.commons.dbutils.QueryRunner;
    import org.apache.commons.dbutils.handlers.BeanListHandler;
    ​
    import java.sql.SQLException;
    import java.util.List;
    ​
    public class TypesDaoImpl implements ITypesDao {
    ​
     private QueryRunner qr = new QueryRunner(DruidUtil.getDataSource());
    ​
    ​
     @Override
     public List getAllTypes() {
         try {
             return qr.query("select * from types", new BeanListHandler(Types.class));
         } catch (SQLException e) {
             throw new RuntimeException(e);
         }
     }
    }
    package com.saas.util;
    ​
    import com.alibaba.druid.pool.DruidDataSource;
    import com.alibaba.druid.pool.DruidDataSourceFactory;
    ​
    import javax.sql.DataSource;
    ​
    public class DruidUtil {
    ​
     private static Env env = Env.getInstance();
    ​
     public static DataSource getDataSource()
     {
         try {
             DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(env);
    ​
             dataSource.setUrl(env.getProperty("url"));
             dataSource.setUsername(env.getProperty("user"));
             dataSource.setPassword(env.getProperty("pass"));
             dataSource.setDriverClassName(env.getProperty("driver"));
    ​
             return dataSource;
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
    }
    package com.saas.util;
    ​
    import java.io.IOException;
    import java.util.Properties;
    ​
    public class Env extends Properties {
    ​
     private static final long serialVersionUID = 1L;
    ​
     private static Env env = new Env();
    ​
     private Env() {
         super();
         try {
             load(getClass().getResourceAsStream("/db.properties"));
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
    ​
     public static Env getInstance() {
         return env;
     }
    ​
     public static String get(String key) {
         return env.getProperty(key);
     }
    }
    driver=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/mi?characterEncoding=utf-8
    user=root
    pass=Abc@1234
    页面代码

    将页面展示出来

  • 相关阅读:
    Tailor:一键式视频智能处理,轻松打造精彩视频!
    算法通关村第十八关:白银挑战-回溯热门问题
    【Nginx26】Nginx学习:日志与镜像流量复制
    linux查看所有用户
    VR+中医骨伤学仿真情景实训教学|英途信息
    深度学习卫星遥感图像检测与识别 -opencv python 目标检测 计算机竞赛
    kafka部分partition的leader=-1修复方案整理
    ISIS——基本概念2(域间路由)
    Web Workers RPC
    云原生数据库的到来
  • 原文地址:https://blog.csdn.net/zpz2001/article/details/139833633