首页 > 其他分享 >day109-smbms准备工作

day109-smbms准备工作

时间:2023-05-28 17:45:44浏览次数:52  
标签:return String void day109 private smbms 准备 Integer public

smbms项目部署环境

创建项目

 <?xml version="1.0" encoding="UTF-8"?>
 ​
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 ​
   <groupId>com.gu</groupId>
   <artifactId>smbms</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>war</packaging>
 ​
   <name>smbms Maven Webapp</name>
   <!-- FIXME change it to the project's website -->
   <url>http://www.example.com</url>
 ​
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <maven.compiler.source>1.7</maven.compiler.source>
     <maven.compiler.target>1.7</maven.compiler.target>
   </properties>
 ​
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.11</version>
       <scope>test</scope>
     </dependency>
 ​
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>
       <version>4.0.1</version>
     </dependency>
 ​
     <dependency>
       <groupId>javax.servlet.jsp</groupId>
       <artifactId>jsp-api</artifactId>
       <version>2.2</version>
     </dependency>
 ​
     <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>8.0.28</version>
     </dependency>
 ​
     <dependency>
       <groupId>javax.servlet.jsp.jstl</groupId>
       <artifactId>jstl-api</artifactId>
       <version>1.2</version>
     </dependency>
 ​
     <dependency>
       <groupId>taglibs</groupId>
       <artifactId>standard</artifactId>
       <version>1.1.2</version>
     </dependency>
   </dependencies>
 ​
 </project>

 

配置web.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                       http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
          version="4.0"
          metadata-complete="true">
     
 <!--    字符编码过滤器-->
     <filter>
         <filter-name>CharacterEncodingFilter</filter-name>
         <filter-class>com.gu.filter.CharacterEncodingFilter</filter-class>
     </filter>
     <filter-mapping>
         <filter-name>CharacterEncodingFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
 </web-app>

 

链接数据库

 
driver=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
 username=root
 password=123456

 

创建数据库公共类

 package com.gu.dao;
 ​
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.*;
 import java.util.Properties;
 ​
 //操作数据库的公共类
 public class BaseDao {
 ​
     private static String driver;
     private static String url;
     private static String username;
     private static String password;
 ​
     //静态代码块,类加载的时候就初始化了
     static {
         //通过类加载器读取相应的资源
         InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
         Properties properties = new Properties();
         try {
             properties.load(is);
         } catch (IOException e) {
             e.printStackTrace();
         }
 ​
         driver = properties.getProperty("driver");
         url = properties.getProperty("url");
         username = properties.getProperty("username");
         password = properties.getProperty("password");
     }
 ​
     //获取数据库链接
     public static Connection getConnection(){
         Connection connection = null;
         try {
             Class.forName(driver);
             connection = DriverManager.getConnection(url,username,password);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
 ​
         return connection;
     }
 ​
     //编写查询公共类
     public static ResultSet execute(Connection connection, String sql,Object[] params,ResultSet resultSet,PreparedStatement preparedStatement) throws SQLException {
         preparedStatement = connection.prepareStatement(sql);
 ​
         for (int i = 0; i < params.length; i++) {
             preparedStatement.setObject(i+1,params[i]);
             
         }
         resultSet = preparedStatement.executeQuery();
         return resultSet;
 ​
     }
 ​
     //编写增删改公共方法
     public static int execute(Connection connection, String sql,Object[] params,PreparedStatement preparedStatement) throws SQLException {
         preparedStatement = connection.prepareStatement(sql);
 ​
         for (int i = 0; i < params.length; i++) {
             preparedStatement.setObject(i+1,params[i]);
 ​
         }
         int updateRows = preparedStatement.executeUpdate();
         return updateRows;
 ​
     }
 ​
     //释放资源
     public static boolean closeResource(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet){
         boolean flag = true;
         if (resultSet != null){
             try {
                 resultSet.close();
                 resultSet = null;
             } catch (SQLException e) {
                 e.printStackTrace();
                 flag = false;
             }
         }
 ​
         if (preparedStatement != null){
             try {
                 preparedStatement.close();
                 preparedStatement = null;
             } catch (SQLException e) {
                 e.printStackTrace();
                 flag = false;
             }
         }
 ​
         if (connection != null){
             try {
                 connection.close();
                 connection = null;
             } catch (SQLException e) {
                 e.printStackTrace();
                 flag = false;
             }
         }
         return flag;
     }
 }

 

创建实体类(以一个为例)

 
package com.gu.pojo;
 ​
 import java.util.Date;
 ​
 public class User {
    private Integer id; //id 
    private String userCode; //用户编码
    private String userName; //用户名称
    private String userPassword; //用户密码
    private Integer gender;  //性别
    private Date birthday;  //出生日期
    private String phone;   //电话
    private String address; //地址
    private Integer userRole;    //用户角色
    private Integer createdBy;   //创建者
    private Date creationDate; //创建时间
    private Integer modifyBy;     //更新者
    private Date modifyDate;   //更新时间
    
    private Integer age;//年龄
    
    private String userRoleName;    //用户角色名称
    
    
    public String getUserRoleName() {
       return userRoleName;
    }
    public void setUserRoleName(String userRoleName) {
       this.userRoleName = userRoleName;
    }
    public Integer getAge() {
       /*long time = System.currentTimeMillis()-birthday.getTime();
       Integer age = Long.valueOf(time/365/24/60/60/1000).IntegerValue();*/
       Date date = new Date();
       Integer age = date.getYear()-birthday.getYear();
       return age;
    }
    public Integer getId() {
       return id;
    }
    public void setId(Integer id) {
       this.id = id;
    }
    public String getUserCode() {
       return userCode;
    }
    public void setUserCode(String userCode) {
       this.userCode = userCode;
    }
    public String getUserName() {
       return userName;
    }
    public void setUserName(String userName) {
       this.userName = userName;
    }
    public String getUserPassword() {
       return userPassword;
    }
    public void setUserPassword(String userPassword) {
       this.userPassword = userPassword;
    }
    public Integer getGender() {
       return gender;
    }
    public void setGender(Integer gender) {
       this.gender = gender;
    }
    public Date getBirthday() {
       return birthday;
    }
    public void setBirthday(Date birthday) {
       this.birthday = birthday;
    }
    public String getPhone() {
       return phone;
    }
    public void setPhone(String phone) {
       this.phone = phone;
    }
    public String getAddress() {
       return address;
    }
    public void setAddress(String address) {
       this.address = address;
    }
    public Integer getUserRole() {
       return userRole;
    }
    public void setUserRole(Integer userRole) {
       this.userRole = userRole;
    }
    public Integer getCreatedBy() {
       return createdBy;
    }
    public void setCreatedBy(Integer createdBy) {
       this.createdBy = createdBy;
    }
    public Date getCreationDate() {
       return creationDate;
    }
    public void setCreationDate(Date creationDate) {
       this.creationDate = creationDate;
    }
    public Integer getModifyBy() {
       return modifyBy;
    }
    public void setModifyBy(Integer modifyBy) {
       this.modifyBy = modifyBy;
    }
    public Date getModifyDate() {
       return modifyDate;
    }
    public void setModifyDate(Date modifyDate) {
       this.modifyDate = modifyDate;
    }
 }

 

设置字符监听器

 package com.gu.filter;
 ​
 import javax.servlet.*;
 import java.io.IOException;
 ​
 public class CharacterEncodingFilter implements Filter {
 ​
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
 ​
     }
 ​
     @Override
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
         servletRequest.setCharacterEncoding("UTF-8");
         servletResponse.setCharacterEncoding("UTF-8");
         filterChain.doFilter(servletRequest, servletResponse);
     }
 ​
     @Override
     public void destroy() {
 ​
     }
 }

 

over

 

标签:return,String,void,day109,private,smbms,准备,Integer,public
From: https://www.cnblogs.com/GUGUZIZI/p/17438543.html

相关文章

  • 答辩准备,知识问题等
    架构和框架的区别框架是一种编程工具,它是一个预定义的结构,包含了一系列的类、函数、方法等,可以帮助开发者快速搭建应用程序,提高开发效率。框架通常提供了一些通用的功能,例如数据库访问、用户认证、会话管理等,开发者可以在此基础上进行二次开发,根据自己的需求进行扩展。架构是一......
  • Elasticsearch掰开揉碎第20篇京东商场之前期准备
    引言上一篇主要讲解的是:京东商场之环境搭建(创建spring项目、设置项目JDK版本、设置项目的编译版本、设置项目的前端规范)本篇主要讲解的是:京东商场之前期准备(引入pom依赖、删除环境中无用的文件、修改资源配置文件、拷贝前端素材、创建测试controller、启动springboot项目、访问......
  • Elasticsearch掰开揉碎第11篇java操作ES前期准备
    引言上一篇主要讲解的是:使用eclipse创建普通java项目\maven项目,使用idea创建普通java项目\maven项目。本篇主要讲解的是:使用java操作Elasticsearch的前期准备(创建索引库、设置mapping、插入数据、验证数据、创建maven项目)前期准备之数据1、创建索引库curl-XPUT'http://192.168......
  • 怎么让下一代准备好迎接更大挑战?
    经济形式不好,大家都知道,怎么办呢? 国家已经提出要走高质量发展道路,不断创新,但问题是,我是从填鸭式教育工厂出来的,我是没有创新能力的,或者说只有一点点的。 我能做到的,就是到网络上看看别人有没有好的想法,然后评估可行性。比如我想要一个真皮的手账本,很贵,大几百。突然发现小红......
  • 杂项 婚礼准备
    目录杂项婚礼准备男方女方杂项婚礼准备男方女方......
  • 要被“枪决”了,应该做些什么准备?
    好兄弟们,今天一早,东东起床想看看最近有什么劲爆消息的时候,突然发现热搜中网友们纷纷都收到了要被“枪决”的通知,这突如其来的大事件,让一惯走在吃瓜最前线的东东瞬间丢掉了因沉浸暴富美梦结果闹钟响了6次后强行起床发现上班即将迟到的慌乱,赶紧仔细看了起来,结果越看越失望原来只是一......
  • 要被“枪决”了,应该做些什么准备?
    好兄弟们,今天一早,东东起床想看看最近有什么劲爆消息的时候,突然发现热搜中网友们纷纷都收到了要被“枪决”的通知,这突如其来的大事件,让一惯走在吃瓜最前线的东东瞬间丢掉了因沉浸暴富美梦结果闹钟响了6次后强行起床发现上班即将迟到的慌乱,赶紧仔细看了起来,结果越看越失望原来只是一......
  • JMeter04-性能测试流程之准备步骤
    性能测试流程性能需求分析测试人员需要与需求人员(客户)、领导及项目相关人员进行沟通,同时收集各种项目资料,对系统进行分析,确认测试的意图;确认客户对性能的态度;重点关注的性能指标。某系统需求中性能部分的说明如下要掌握哪些性能测试需求系统响应时间要求每秒完成的业......
  • 求矩阵的值_为多表代换密码解密做准备
    介绍:先输入n,然后输入n*n矩阵,最后输出矩阵的值。#include<bits/stdc++.h>usingnamespacestd;floatresult;intA[1010][1010];floatAA[1010][1010];intn;voidSwap(float*a,float*b){for(inti=1;i<=n;++i){floattemp=a[i];......
  • 架构活动复盘前的准备工作
    在进入复盘环节之前,我们需要做一些准备工作:建设复盘氛围:为参与者提供一个安全且平衡的复盘环境。梳理错失的机会点:从公司层面的宏观视角看,错失的最可惜的机会点是什么?提前梳理重大机会点,可以帮助我们控制复盘节奏,避免复盘成为一个裸心会,被一个麦霸引导到他个人的心灵独白中去。设定......