精华内容
下载资源
问答
  • jsp实现增删改查的实例,里面有数据库和javaBean代码可以供你参考 jsp实现增删改查的实例,里面有数据库和javaBean代码可以供你参考
  • jsp中尝试打印 测试成功的连接 数据库操作 建库 CREATE DATABASE news CHARACTER SET utf8; 建表 CREATE TABLE article( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, title VARCHAR(20) NOT NULL, ...

    项目搭建

    新建项目

    在这里插入图片描述

    布局驱动

    在这里插入图片描述

    布置工具

    在这里插入图片描述

    把tools工具放到src目录中

    配置中需要修改的内容

    在这里插入图片描述

    测试一下连接是否可以拿到

    在这里插入图片描述
    在jsp中尝试打印

    在这里插入图片描述

    测试成功的连接

    在这里插入图片描述

    数据库操作

    演

    建库

    CREATE DATABASE news CHARACTER SET utf8;
    

    在这里插入图片描述

    建表

    CREATE TABLE article(
    	id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    	title VARCHAR(20) NOT NULL,
    	content VARCHAR(200) NOT NULL
    );
    

    在这里插入图片描述

    插入数据

    INSERT INTO article VALUES(NULL,'六一儿童节去哪玩','武汉有很多好玩的地点。。。');
    

    在这里插入图片描述

    继续插入数据

    INSERT INTO article VALUES(NULL,'2021下半年还有哪些假日','中秋节,国庆节,双十一,端午节。。。');
    
    

    在这里插入图片描述

    当前数据

    在这里插入图片描述

    展开全文
  • servlet: 1.可以使java代码成为资源被url访问,并且将一次访问生成请求和响应封装成对象 2.可以通过请求对象拿用户输入的参数 3.可以通过响应对象把结果响应给...servlet里最烦的是要拼接html片段所有引入jsp ...

    servlet:
    1.可以使java代码成为资源被url访问,并且将一次访问生成请求和响应封装成对象
    2.可以通过请求对象拿用户输入的参数
    3.可以通过响应对象把结果响应给浏览器呈现给用户看

    servlet里最烦的是要拼接html片段所有引入jsp
    重点的就是:jsp是一种可以在html页面插入java的技术,他能解决servlet的html片段拼接问题,并且也能解决html页面能访问不能做处理(拿到用户输入参数)的问题.
    语法:
    <%里面写java代码%>
    <%=写获取的变量值或方法%>

    1.页面展示localhost:8080/emp
    1.当页面地址栏发出请求,那么此时回去找一个叫emp的servlet,会进入到doGet方法
    2.在doGet方法内部做了乱码处理,会获得参数为action的值,由于请求只有emp,所以此时action得到的为null
    3.由于action为null,那么此时会进入到show()方法
    4.在show方法中调用了service中getAll的方法,service中getAll方法调用dao中selectEmps()的方法
    5.selectEmps方法对数据库执行select* from emp的语句,将查询的结果封装成List集合
    6.将得到的结果逐层通过dao和service返回给Controller
    7.将集合封装进request,并且此时是键为list的attrbute,将requset带着attrbute传给emp.jsp
    8.emp.jsp渲染数据
    a.emp.jsp中首先从请求中拿到键为list的attrbute的值,强转为List;
    b.遍历这个list集合,遍历的过程中循环生成一行一行的tr(list中每一个对象就是一行数据),将属性值通过<%= %>的形式输出到页面
    注意:我们在这里拼接了修改和删除的url
    2.页面的增加功能<用户点击增加按钮>
    1.当用户点击增加按钮,浏览器通过a标签的锚链接发了一个http://localhost:8080/add.html
    2.此时页面将会跳转到add.html进行展示
    3.当用户输入完增加的属性,点击增加按钮,此时浏览器会根据from表单的action属性值,将参数封装成url,发出一个为localhost:8080/emp?action=add&empno=7777&ename=张三
    4.此时服务器会解读url,找到emp的controller,进入到doGet()方法
    5.在doGet请求中,拿到action的值为add,根据判断,会进入到add()方法
    6.在add方法中拿到用户输入的值,封装成对象emp,调用service的add方法将emp传进去,service回去调用dao的insert方法,inserrt方法执行sql语句,将内容插入数据库,将结果逐层返回给controller
    7.controller根据结果选择相应的视图来展示插入的结果,插入成功,重定向到localhost:8080/emp,
    8.由于浏览器重新发送localhost:8080/emp,重复执行1,。页面展示功能
    3.页面的删除功能<当用户点击每行数据后面的删除功能时>
    1.在页面渲染的时候,就将每一行的empno渲染进删除a标签的锚链接,当点击删除按钮,浏览器地址栏会发生修改,发出localhost:8080/emp?action=del&empno=7369
    2.此时服务器会解读url,找到emp的controller,进入到doGet()方法
    3.在doGet请求中,拿到action的值为del,根据判断,会进入到del()方法
    4.在del()方法中获取要删除的那一行的deptno参数,调用service的remove方法,remove回去调用dao中del方法,执行相关的sql语句,将结果逐层返回给Controller
    5.controller根据结果选择相应的视图来展示删除的结果,删除成功,重定向到localhost:8080/emp,
    6.由于浏览器重新发送localhost:8080/emp,重复执行1,。页面展示功能
    4.页面的查找功能<当用户在查找框输入值,点击查找时>
    考虑到用户体验,我们将查找功能设计为支持模糊查询
    1.当用户在查找框输入姓名的模糊字段,点击查找按钮提交时,那么此时from表单会将参数通过urllocalhost:8080/emp?action=serarch传递给相应的controller
    2.此时服务器会解读url,找到emp的controller,进入到doGet()方法
    3.在doGet请求中,拿到action的值为serarch,根据判断,会进入到serarch()方法
    4.在serarch方法中拿到用户输入的模糊查询字段,交给service==>dao,执行模糊查询语句,得到List,并且将结果返回给Controller
    5.将集合封装进request,并且此时是键为list的attrbute,将requset带着attrbute传给emp.jsp
    6.emp.jsp渲染数据
    a.emp.jsp中首先从请求中拿到键为list的attrbute的值,强转为List;
    b.遍历这个list集合,遍历的过程中循环生成一行一行的tr(list中每一个对象就是一行数据),将属性值通过<%= %>的形式输出到页面
    5.页面的修改功能<当用户点击修改按钮时>
    修改的第一个步骤应该是查,将查出来数据展示form表单上让用户修改,当用户完成修改时,收集用户输入的值,去数据库修改数据
    1.在页面渲染的时候,就将每一行的empno渲染进修改a标签的锚链接,当点击修改按钮,浏览器地址栏会发生修改,发出localhost:8080/emp?action=updateSelect&empno=7369
    2.此时服务器会解读url,找到emp的controller,进入到doGet()方法
    3.在doGet请求中,拿到action的值为updateSelect根据判断,会进入到del()方法
    4.在updateSelect方法内,拿到empno,交给service==>dao查询出一个emp对象,
    5.controller需要选择相应的视图,将数据传递过去,使视图进行渲染,带着emp对象调到update.jsp中
    6.在update.jsp中拿到request请求传过来emp对象
    7.在from表单的各个控件中,将emp对象的属性值通过<%= %>渲染给控件的value属性
    需要注意的是:修改条件的值不能被用户修改,但是这个值又必须要保留下来
    那么只能处理控件为只读或者隐藏
    8.当用户输入完修改值时,点击更新按钮,会将参数封装到form表单的action指向的url,发出http://localhost:8080/emp?action=update
    9.找controller==>action==>update==>service==>dao==>执行sql语句,将结果逐层返回给controller
    10.controller选择相应的视图进行跳转

    展开全文
  • 实现添加 dao层 [java]   view plain   copy public   boolean  addEmployee(Employee employee){   String sql =  "INSERT INTO `employee`(`EmployeeName`,`EmployeeSex`,`EmployeePhone`,`...

    deme的结构图,采用的是三层架构,降低耦合度。


    public class DBHelper {
    	//属性,必须为私有变量
    	private Connection conn;
    	private Statement state;
    	private PreparedStatement prep;
    	
    	//构造方法
    	public DBHelper(){
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    			conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","root");
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    	//方法
    		//增删改
    		public int update(String sql) throws SQLException{
    			state=conn.createStatement();
    			int temp=prep.executeUpdate(sql);  //增删改最后要返回一个整形变量
    	  	return  temp;
    		}
    		//方法重载,当所变化的变量个数不确定的时候,就要用到表达式
    		public int update(String sql,Object ... arr) throws SQLException{
    			prep=conn.prepareStatement(sql);
    			//给问号赋值
    			for(int i=0;i<arr.length;i++){
    				prep.setObject(i+1, arr[i]);
    			}
    			return prep.executeUpdate();
    		} 
    		
    		//查询
    		public ResultSet select(String sql) throws SQLException{
    			state=conn.createStatement();
    			ResultSet rs=state.executeQuery(sql);
    		return rs;
    		}
    		public ResultSet select(String sql,Object ... arr) throws SQLException{
    			prep=conn.prepareStatement(sql);
    			for(int i=0;i<arr.length;i++){ 
    				prep.setObject(i+1, arr[i]);  //提取数据,索引从零开始,所以会i+1;
    			}
    			return prep.executeQuery();
    		}
    		
    		//关闭
    		public void closeAll() throws SQLException{
    			if(state!=null && !state.isClosed()) state.close();
    			if(prep!=null && !prep.isClosed()) prep.close();
    			if(conn!=null && !conn.isClosed()) conn.close();
    		}
    	
    }
    
    //完成一个插入操作
    public class Demo4 {
    	public static void main(String[] args) {
    	  String username="xi";
    	  String userpass="fei";
    	  DBHelp hp=new DBHelp();
    	  String sql="insert into users values(?,?)";
    	  try {
    		int temp=hp.update(sql,username,userpass);
    		System.out.println(temp);
    	} catch (SQLException e) {
    				e.printStackTrace();
    	}
    	  
    	}
    
    }
    注意:ResultSet  中的next() 将指针移动到下一条记录,不允许有空指针
    	public static void main(String[] args) {
    		System.out.println(getConnection());
    	}
    测试一下,是否连接成功

    连接成功

    接下来创建实体类Employee

    [java] view plain copy
    1. import java.io.Serializable;  
    2.   
    3. public class Employee implements Serializable{  
    4.   
    5.     /** 
    6.      *  
    7.      */  
    8.     private static final long serialVersionUID = 1L;  
    9.     //   ps:写属性推荐一个冷门的快捷键 shift+alt+a  谁用谁知道  
    10.     private int employeeId;  
    11.     private String employeeName;  
    12.     private String employeeSex;  
    13.     private String employeePhone;  
    14.     private String employeeEmail;  
    15.       
    16.     // shift+alt+s   选择Generate Getters and setters to create  生成get set方法   
    17.     public int getEmployeeId() {  
    18.         return employeeId;  
    19.     }  
    20.     public void setEmployeeId(int employeeId) {  
    21.         this.employeeId = employeeId;  
    22.     }  
    23.     public String getEmployeeName() {  
    24.         return employeeName;  
    25.     }  
    26.     public void setEmployeeName(String employeeName) {  
    27.         this.employeeName = employeeName;  
    28.     }  
    29.     public String getEmployeeSex() {  
    30.         return employeeSex;  
    31.     }  
    32.     public void setEmployeeSex(String employeeSex) {  
    33.         this.employeeSex = employeeSex;  
    34.     }  
    35.     public String getEmployeePhone() {  
    36.         return employeePhone;  
    37.     }  
    38.     public void setEmployeePhone(String employeePhone) {  
    39.         this.employeePhone = employeePhone;  
    40.     }  
    41.     public String getEmployeeEmail() {  
    42.         return employeeEmail;  
    43.     }  
    44.     public void setEmployeeEmail(String employeeEmail) {  
    45.         this.employeeEmail = employeeEmail;  
    46.     }  
    47. }  

    查询列表

    DAO里写方法

    [java] view plain copy
    1. public List<Employee> getAllEmployee(){  
    2.     List<Employee> list = new ArrayList<Employee>();  
    3.     Connection conn = DBHelper.getConnection();  
    4.     String sql  = "select * from Employee";  
    5.     try {  
    6.         PreparedStatement pst = conn.prepareStatement(sql);  
    7.         ResultSet rst = pst.executeQuery();  
    8.         while (rst.next()) {  
    9.             Employee employee = new Employee();  
    10.             employee.setEmployeeEmail(rst.getString("EmployeeEmail"));  
    11.             employee.setEmployeeId(rst.getInt("EmployeeId"));  
    12.             employee.setEmployeeName(rst.getString("EmployeeName"));  
    13.             employee.setEmployeePhone(rst.getString("EmployeePhone"));  
    14.             employee.setEmployeeSex(rst.getString("EmployeeSex"));  
    15.             list.add(employee);  
    16.         }  
    17.         rst.close();  
    18.         pst.close();  
    19.     } catch (SQLException e) {  
    20.         e.printStackTrace();  
    21.     }  
    22.     return list;  
    23. }  

    自动创建一个servlet类,或者继承HttpServlet类。

    [java] view plain copy
    1. public class EmployeeShowServlet  extends HttpServlet{  
    2.   
    3.     private static final long serialVersionUID = 1L;  
    4.   
    5.     @Override  
    6.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
    7.             throws ServletException, IOException {  
    8.         this.doPost(req, resp);  
    9.     }  
    10.   
    11.     @Override  
    12.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    13.             throws ServletException, IOException {  
    14.         EmployeeDao dao = new EmployeeDao();  
    15.         List<Employee> list = dao.getAllEmployee();  
    16.         req.setAttribute("list", list);  
    17.         req.getRequestDispatcher("index.jsp").forward(req, resp);  
    18.     }  
    19.       
    20.       
    21. }  

    最后在xml文件里面配置写好的servlet

    [html] view plain copy
    1. <servlet>  
    2.     <servlet-name>employeeShowServlet</servlet-name>  
    3.     <servlet-class>com.xgyb.servlet.EmployeeShowServlet</servlet-class>  
    4. </servlet>  
    5. <servlet-mapping>  
    6.     <servlet-name>employeeShowServlet</servlet-name>  
    7.     <url-pattern>/employeeShowServlet</url-pattern>  
    8. </servlet-mapping>  

    jsp页面

    [html] view plain copy
    1. <table>  
    2.     <tr>  
    3.         <td>编号</td>  
    4.         <td>姓名</td>  
    5.         <td>性别</td>  
    6.         <td>电话</td>  
    7.         <td>邮箱</td>  
    8.         <td>操作</td>  
    9.     </tr>  
    10.     <c:forEach items="${list}" var="item">  
    11.         <tr>  
    12.             <td>${item.employeeId }</td>  
    13.             <td>${item.employeeName }</td>  
    14.             <td>${item.employeeSex }</td>  
    15.             <td>${item.employeePhone }</td>  
    16.             <td>${item.employeeEmail }</td>  
    17.         </tr>  
    18.     </c:forEach>  
    19.    </table>  
    启动tomcat      在浏览器输入:http://localhost:8080/EmployeeManager/employeeShowServlet


    实现添加

    dao层

    [java] view plain copy
    1. public boolean addEmployee(Employee employee){  
    2.         String sql = "INSERT INTO `employee`(`EmployeeName`,`EmployeeSex`,`EmployeePhone`,`EmployeeEmail`) VALUES (?,?,?,?)";  
    3.         Connection conn = DBHelper.getConnection();  
    4.         try {  
    5.             PreparedStatement pst = conn.prepareStatement(sql);  
    6.             pst.setString(1, employee.getEmployeeName());  
    7.             pst.setString(2, employee.getEmployeeSex());  
    8.             pst.setString(3, employee.getEmployeePhone());  
    9.             pst.setString(4, employee.getEmployeeEmail());  
    10.             int count = pst.executeUpdate();  
    11.             pst.close();  
    12.             return count>0?true:false;  
    13.         } catch (SQLException e) {  
    14.             e.printStackTrace();  
    15.         }  
    16.         return false;  
    17.     }  

    创建EmployeeAddServlet

    [java] view plain copy
    1. public class EmployeeAddServlet extends HttpServlet{  
    2.     private static final long serialVersionUID = 1L;  
    3.   
    4.     @Override  
    5.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
    6.             throws ServletException, IOException {  
    7.         this.doPost(req, resp);  
    8.     }  
    9.   
    10.     @Override  
    11.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    12.             throws ServletException, IOException {  
    13.         String employeeName = req.getParameter("employeeName");  
    14.         String employeeSex = req.getParameter("employeeSex");  
    15.         String employeePhone = req.getParameter("employeePhone");  
    16.         String employeeEmail = req.getParameter("employeeEmail");  
    17.         Employee employee = new Employee();  
    18.         employee.setEmployeeEmail(employeeEmail);  
    19.         employee.setEmployeeName(new String(employeeName.getBytes("ISO-8859-1"),"UTF-8"));  
    20.         employee.setEmployeePhone(employeePhone);  
    21.         employee.setEmployeeSex(new String(employeeSex.getBytes("ISO-8859-1"),"UTF-8"));  
    22.         EmployeeDao dao = new EmployeeDao();  
    23.         dao.addEmployee(employee);  
    24.         req.getRequestDispatcher("employeeShowServlet").forward(req, resp);  
    25.     }  
    26. }  

    xml配置

    [html] view plain copy
    1. <servlet>  
    2.     <servlet-name>employeeAddServlet</servlet-name>  
    3.     <servlet-class>com.xgyb.servlet.EmployeeAddServlet</servlet-class>  
    4. </servlet>  
    5. <servlet-mapping>  
    6.     <servlet-name>employeeAddServlet</servlet-name>  
    7.     <url-pattern>/employeeAddServlet</url-pattern>  
    8. </servlet-mapping>  

    jsp

    [html] view plain copy
    1. <form action="employeeAddServlet" method="post">  
    2.   <table border="1">  
    3.     <tr>  
    4.         <td colspan="2"><h1>添加员工</h1></td>  
    5.     </tr>  
    6.     <tr>  
    7.         <td>姓名:</td>  
    8.         <td><input  type="text" name="employeeName"/></td>  
    9.     </tr>  
    10.     <tr>  
    11.         <td>性别:</td>  
    12.         <td><input  type="text" name="employeeSex"/></td>  
    13.     </tr>  
    14.     <tr>  
    15.         <td>电话:</td>  
    16.         <td><input  type="text" name="employeePhone"/></td>  
    17.     </tr>  
    18.     <tr>  
    19.         <td>邮箱:</td>  
    20.         <td><input  type="text" name="employeeEmail"/></td>  
    21.     </tr>  
    22.     <tr>  
    23.         <td colspan="2"><input  type="submit" value="提交"/></td>  
    24.     </tr>  
    25.   </table>  
    26.  </form>  
    输入:http://localhost:8080/EmployeeManager/addEmployee.jsp


    添加成功                                        

    Dao  修改有两个,根据id选中需要修改的内容

    [java] view plain copy
    1. public boolean updateEmployee(Employee employee){  
    2.         String sql = "UPDATE `employee` SET `EmployeeName`=?,`EmployeeSex`=?,`EmployeePhone`=?,`EmployeeEmail`=? WHERE `EmployeeId` = ?";  
    3.         Connection conn = DBHelper.getConnection();  
    4.         try {  
    5.             PreparedStatement pst = conn.prepareStatement(sql);  
    6.             pst.setString(1, employee.getEmployeeName());  
    7.             pst.setString(2, employee.getEmployeeSex());  
    8.             pst.setString(3, employee.getEmployeePhone());  
    9.             pst.setString(4, employee.getEmployeeEmail());  
    10.             pst.setInt(5, employee.getEmployeeId());  
    11.             int count = pst.executeUpdate();  
    12.             pst.close();  
    13.             return count>0?true:false;  
    14.         } catch (SQLException e) {  
    15.             e.printStackTrace();  
    16.         }  
    17.         return false;  
    18.     }  
    [java] view plain copy
    1. public Employee selectEmployeeById(int id){  
    2.         Connection conn = DBHelper.getConnection();  
    3.         String sql  = "select * from Employee where EmployeeId = "+id;  
    4.         Employee employee = null;  
    5.         try {  
    6.             PreparedStatement pst = conn.prepareStatement(sql);  
    7.             ResultSet rst = pst.executeQuery();  
    8.             while (rst.next()) {  
    9.                 employee = new Employee();  
    10.                 employee.setEmployeeEmail(rst.getString("EmployeeEmail"));  
    11.                 employee.setEmployeeId(rst.getInt("EmployeeId"));  
    12.                 employee.setEmployeeName(rst.getString("EmployeeName"));  
    13.                 employee.setEmployeePhone(rst.getString("EmployeePhone"));  
    14.                 employee.setEmployeeSex(rst.getString("EmployeeSex"));  
    15.             }  
    16.             rst.close();  
    17.             pst.close();  
    18.         } catch (SQLException e) {  
    19.             e.printStackTrace();  
    20.         }  
    21.         return employee;  
    22.     }  

    Servlet

    [java] view plain copy
    1. public class EmployeeupdateServlet extends HttpServlet{  
    2.   
    3.     private static final long serialVersionUID = 1L;  
    4.   
    5.     @Override  
    6.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
    7.             throws ServletException, IOException {  
    8.         String idStr = req.getParameter("id");  
    9.         if(idStr != null && !idStr.equals("")){  
    10.             int id = Integer.valueOf(idStr);  
    11.             EmployeeDao dao = new EmployeeDao();  
    12.             Employee employee = dao.selectEmployeeById(id);  
    13.             req.setAttribute("employee", employee);  
    14.         }  
    15.         req.getRequestDispatcher("updateEmployee.jsp").forward(req, resp);  
    16.           
    17.     }  
    18.   
    19.     @Override  
    20.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    21.             throws ServletException, IOException {  
    22.         String employeeName = req.getParameter("employeeName");  
    23.         String employeeSex = req.getParameter("employeeSex");  
    24.         String employeePhone = req.getParameter("employeePhone");  
    25.         String employeeEmail = req.getParameter("employeeEmail");  
    26.         String idStr = req.getParameter("employeeId");  
    27.         Employee employee = new Employee();  
    28.         employee.setEmployeeId(Integer.valueOf(idStr));  
    29.         employee.setEmployeeEmail(employeeEmail);  
    30.         employee.setEmployeeName(new String(employeeName.getBytes("ISO-8859-1"),"UTF-8"));  
    31.         employee.setEmployeePhone(employeePhone);  
    32.         employee.setEmployeeSex(new String(employeeSex.getBytes("ISO-8859-1"),"UTF-8"));  
    33.         EmployeeDao dao = new EmployeeDao();  
    34.         dao.updateEmployee(employee);  
    35.         req.getRequestDispatcher("employeeShowServlet").forward(req, resp);  
    36.     }  
    37. }  

    跟前篇一样需要在xml 配置一下,这个很简单自己试着写。

    修改用的页面就是增加的页面。


    至尊宝  改成了孙悟空。

    Dao  修改有两个,根据id选中需要修改的内容

    [java] view plain copy
    1. public boolean updateEmployee(Employee employee){  
    2.         String sql = "UPDATE `employee` SET `EmployeeName`=?,`EmployeeSex`=?,`EmployeePhone`=?,`EmployeeEmail`=? WHERE `EmployeeId` = ?";  
    3.         Connection conn = DBHelper.getConnection();  
    4.         try {  
    5.             PreparedStatement pst = conn.prepareStatement(sql);  
    6.             pst.setString(1, employee.getEmployeeName());  
    7.             pst.setString(2, employee.getEmployeeSex());  
    8.             pst.setString(3, employee.getEmployeePhone());  
    9.             pst.setString(4, employee.getEmployeeEmail());  
    10.             pst.setInt(5, employee.getEmployeeId());  
    11.             int count = pst.executeUpdate();  
    12.             pst.close();  
    13.             return count>0?true:false;  
    14.         } catch (SQLException e) {  
    15.             e.printStackTrace();  
    16.         }  
    17.         return false;  
    18.     }  
    [java] view plain copy
    1. public Employee selectEmployeeById(int id){  
    2.         Connection conn = DBHelper.getConnection();  
    3.         String sql  = "select * from Employee where EmployeeId = "+id;  
    4.         Employee employee = null;  
    5.         try {  
    6.             PreparedStatement pst = conn.prepareStatement(sql);  
    7.             ResultSet rst = pst.executeQuery();  
    8.             while (rst.next()) {  
    9.                 employee = new Employee();  
    10.                 employee.setEmployeeEmail(rst.getString("EmployeeEmail"));  
    11.                 employee.setEmployeeId(rst.getInt("EmployeeId"));  
    12.                 employee.setEmployeeName(rst.getString("EmployeeName"));  
    13.                 employee.setEmployeePhone(rst.getString("EmployeePhone"));  
    14.                 employee.setEmployeeSex(rst.getString("EmployeeSex"));  
    15.             }  
    16.             rst.close();  
    17.             pst.close();  
    18.         } catch (SQLException e) {  
    19.             e.printStackTrace();  
    20.         }  
    21.         return employee;  
    22.     }  

    Servlet

    [java] view plain copy
    1. public class EmployeeupdateServlet extends HttpServlet{  
    2.   
    3.     private static final long serialVersionUID = 1L;  
    4.   
    5.     @Override  
    6.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
    7.             throws ServletException, IOException {  
    8.         String idStr = req.getParameter("id");  
    9.         if(idStr != null && !idStr.equals("")){  
    10.             int id = Integer.valueOf(idStr);  
    11.             EmployeeDao dao = new EmployeeDao();  
    12.             Employee employee = dao.selectEmployeeById(id);  
    13.             req.setAttribute("employee", employee);  
    14.         }  
    15.         req.getRequestDispatcher("updateEmployee.jsp").forward(req, resp);  
    16.           
    17.     }  
    18.   
    19.     @Override  
    20.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    21.             throws ServletException, IOException {  
    22.         String employeeName = req.getParameter("employeeName");  
    23.         String employeeSex = req.getParameter("employeeSex");  
    24.         String employeePhone = req.getParameter("employeePhone");  
    25.         String employeeEmail = req.getParameter("employeeEmail");  
    26.         String idStr = req.getParameter("employeeId");  
    27.         Employee employee = new Employee();  
    28.         employee.setEmployeeId(Integer.valueOf(idStr));  
    29.         employee.setEmployeeEmail(employeeEmail);  
    30.         employee.setEmployeeName(new String(employeeName.getBytes("ISO-8859-1"),"UTF-8"));  
    31.         employee.setEmployeePhone(employeePhone);  
    32.         employee.setEmployeeSex(new String(employeeSex.getBytes("ISO-8859-1"),"UTF-8"));  
    33.         EmployeeDao dao = new EmployeeDao();  
    34.         dao.updateEmployee(employee);  
    35.         req.getRequestDispatcher("employeeShowServlet").forward(req, resp);  
    36.     }  
    37. }  

    跟前篇一样需要在xml 配置一下,这个很简单自己试着写。

    修改用的页面就是增加的页面。


    至尊宝  改成了孙悟空。

    删除就非常简单了,根据id来删除人物。

    [java] view plain copy
    1. public boolean deleteEmployee(int id){  
    2.         String sql = "delete from Employee where EmployeeId = ?";  
    3.         Connection conn = DBHelper.getConnection();  
    4.         try {  
    5.             PreparedStatement pst = conn.prepareStatement(sql);  
    6.             pst.setInt(1, id);  
    7.             int count = pst.executeUpdate();  
    8.             pst.close();  
    9.             return count>0?true:false;  
    10.         } catch (SQLException e) {  
    11.             e.printStackTrace();  
    12.         }  
    13.         return false;  
    14.     }  
    servlet

    [java] view plain copy
    1. public class EmployeeDeleteServlet extends HttpServlet{  
    2.   
    3.     private static final long serialVersionUID = 1L;  
    4.   
    5.     @Override  
    6.     protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
    7.             throws ServletException, IOException {  
    8.         this.doPost(req, resp);  
    9.     }  
    10.   
    11.     @Override  
    12.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    13.             throws ServletException, IOException {  
    14.         String idStr = req.getParameter("id");  
    15.         if(idStr != null && !idStr.equals("")){  
    16.             int id = Integer.valueOf(idStr);  
    17.             EmployeeDao dao = new EmployeeDao();  
    18.             dao.deleteEmployee(id);  
    19.         }  
    20.         req.getRequestDispatcher("employeeShowServlet").forward(req, resp);  
    21.     }  
    22. }  
    别忘了配置xml文件

    牛魔王被删掉了,是不是很简单。


    http://download.csdn.net/download/alexander_yun/10129982       

    项目的代码,建议手动敲完


    展开全文
  • spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp (6)、mapper < ? xml version = "1.0" encoding = "UTF-8" ? > < ! DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...

    1、搭建环境

    (1)、搭建环境准备工作

    a、官网下载eclipse
    b、官网下载maven,并配置maven环境,和本地仓库路径
    c、eclipse配置maven
    在这里插入图片描述
    在这里插入图片描述

    (2)、新建项目

    (1)file—》new—》maven project
    在这里插入图片描述
    (2)点击next
    在这里插入图片描述
    (3)next
    在这里插入图片描述
    (4)finish完成
    (5)哈哈到此环境就搭建完了

    2、代码和框架构架

    在这里插入图片描述
    (1)、dao

    @Mapper
    public interface UserDAO extends BaseMapper<User> {
    
    	List<User> selectUser();
    
    	List<User> selectByUserId(String userId);
    
    	User selectOneById(String userId);
    
    	void addUser(User user);
    
    	void updateUser(User user);
    
    	void deleteByUserId(String userId);
    }
    

    (2)、server

    public interface UserService {
    	List<User> getUser();
    
    	void addUser(User user);
    
    	List<User> selectByUserId(String userId);
    
    	void updateUser(User user);
    
    	void deleteByUserId(String userId);
    
    	User selectOneById(String userId);
    }
    

    (3)、serverimpl

    @Service("userService")
    public class UserServiceImpl implements UserService {
    
    	@Autowired
    	private UserDAO userDao;
    
    	@Override
    	public List<User> getUser() {
    		return userDao.selectUser();
    	}
    
    	@Override
    	public void addUser(User user) {
    		userDao.addUser(user);
    	}
    
    	@Override
    	public List<User> selectByUserId(String userId) {
    		List<User> selectByUserId = userDao.selectByUserId(userId);
    		return selectByUserId;
    	}
    
    	@Override
    	public void updateUser(User user) {
    		userDao.updateUser(user);
    	}
    
    	@Override
    	public void deleteByUserId(String userId) {
    		userDao.deleteByUserId(userId);
    	}
    
    	@Override
    	public User selectOneById(String userId) {
    		return userDao.selectOneById(userId);
    	}
    
    }
    

    (4)、entity

    public class User {
    
    	  private String userId ;
    	  private String userCode ;
    	  private String userName;
    		public String getUserId() {
    			return userId;
    		}
    		public void setUserId(String userId) {
    			this.userId = userId;
    		}
    		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;
    		}
    		@Override
    		public String toString() {
    			return "User [userId=" + userId + ", userCode=" + userCode + ", userName=" + userName + "]";
    		}
    		  
    	}
    

    (5)、application.properties

    server.port=8081
    context-path:/demoWeb
    
    spring.application.name=demoWeb
    server.tomcat.uri-encoding=utf-8
     
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url = jdbc:mysql://localhost:3306/mysql?setUnicode=true&characterEncoding=utf8
    spring.datasource.username=root
    spring.datasource.password=123456
    spring.datasource.max-idle=10
    spring.datasource.max-wait=10000
    spring.datasource.min-idle=5
    spring.datasource.initial-size=5
     
    server.servlet.session.timeout=30m
    mybatis.typeAliasesPackage=com.springboot.entity
    mybatis.mapper-locations=classpath:mapper/*Mapper.xml
    
    spring.thymeleaf.content-type: text/html 
    spring.thymeleaf.cache: false
    spring.thymeleaf.mode: LEGACYHTML5
    
    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    
    

    (6)、mapper

    <?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.springboot.dao.UserDAO">
    
        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.springboot.entity.User">
            <id column="userId" property="userId" />
            <result column="userCode" property="userCode" />
            <result column="userName" property="userName" />
        </resultMap>
    	<select id="selectUser"  resultType="com.springboot.entity.User">
            SELECT * FROM userstu
        </select>
        <select id="selectByUserId"  resultType="com.springboot.entity.User" parameterType="String">
            SELECT * FROM userstu where userId=#{userId}
        </select>
        
        <select id="selectOneById"  resultType="com.springboot.entity.User" parameterType="String">
            SELECT * FROM userstu where userId=#{userId}
        </select>
        
        <insert id="addUser" parameterType="com.springboot.entity.User">
        	insert into userstu(userId,userCode,userName)values(#{userId},#{userCode},#{userName})
        </insert>
        
        <update id="updateUser" parameterType="com.springboot.entity.User">
        	update userstu set userCode = #{userCode},userName = #{userName} where userId = #{userId}
        </update>
        
        <delete id="deleteByUserId" parameterType="String">
        	delete from userstu where userId = #{userId}
        </delete>
    </mapper>
    

    (7)、controller

    @Controller
    @RequestMapping("test")
    public class UserController {
    
    	@Autowired
    	private UserService userService;
    
    	@ApiOperation(value = "获取用户列表")
    	@RequestMapping("index")
    	public ModelAndView select() {
    		ModelAndView mv = new ModelAndView();
    		List<User> user = userService.getUser();
    		mv.addObject("user", user);
    		mv.setViewName("index");
    		return mv;
    	}
    
    	// 通过id删除学生信息
    	@RequestMapping("/deleteStudentById")
    	public String deleteStudent(String id) {
    		userService.deleteByUserId(id);
    		return "redirect:index";
    	}
    
    	// 通过id查询学生的信息
    	@RequestMapping("/selectStudentById")
    	public ModelAndView selectStudentById(String id) {
    		ModelAndView mv = new ModelAndView();// 创建模型视图对象
    		List<User> user = userService.selectByUserId(id);
    		mv.addObject("user", user);
    		mv.setViewName("selectOne");
    		return mv;
    	}
    
    	// 通过id信息(更新学生信息)
    	@RequestMapping("/selectOneUserById")
    	public ModelAndView selectOneUserByIds(String id) {
    		ModelAndView mv = new ModelAndView();
    		User user = userService.selectOneById(id);
    		mv.addObject("user", user);
    		mv.setViewName("update");
    		return mv;
    	}
    
    	// 通过id信息
    	@RequestMapping("/updateStudentById")
    	public String updateStudent(User user) {
    		userService.updateUser(user);
    		return "redirect:index";
    	}
    
    	// 通过id信息
    	@RequestMapping("/addUser")
    	public String addUsers(User user) {
    		userService.addUser(user);
    		return "redirect:index";
    	}
    
    	@RequestMapping("/add")
    	public ModelAndView addController(User user) {
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("add");
    		return mv;
    	}
    
    	@RequestMapping("/adminLeft")
    	public ModelAndView adminLef() {
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("adminLeft");
    		return mv;
    	}
    
    	@RequestMapping("/indexUser")
    	public ModelAndView indexUser() {
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("adminIndex");
    		return mv;
    	}
    
    	@RequestMapping("/adminList")
    	public ModelAndView adminLis() {
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("adminList");
    		return mv;
    	}
    
    	@RequestMapping("/adminTop")
    	public ModelAndView adminTo() {
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("adminTop");
    		return mv;
    	}
    
    }
    

    (8)、Application.java

    @MapperScan("com.springboot.dao")
    @EnableCaching
    @EnableAutoConfiguration(exclude = { JpaRepositoriesAutoConfiguration.class })
    @SpringBootApplication(exclude = { DataSourceTransactionManagerAutoConfiguration.class })
    public class Application {
    	public static void main(String[] args) {
    		SpringApplication.run(Application.class, args);
    	}
    }
    

    (9)、jsp
    1 index.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    	pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    .tab {
    	border-top: 1px solid #000;
    	border-left: 1px solid #000;
    	text-align: center
    }
    
    .tab td {
    	border-bottom: 1px solid #000;
    	border-right: 1px solid #000;
    }
    
    #header {
    	background-color: #5CADAD;
    	color: white;
    	text-align: center;
    	padding: 5px;
    }
    
    #nav {
    	line-height: 30px;
    	background-color: #B3D9D9;
    	height: 500px;
    	width: 100px;
    	float: left;
    	padding: 5px;
    	text-align: center;
    }
    
    #section {
    	height: 500px;
    	width: 1212px;
    	background-color: #F5F5F5;
    	text-align: center;
    	float: left;
    	padding: 5px;
    	color: blue;
    }
    
    #footer {
    	background-color: #B3D9D9;
    	color: white;
    	clear: both;
    	text-align: center;
    	padding: 5px;
    }
    </style>
    
    </head>
    <body>
    	<div id="header">
    		<h1>Welcome to my world!</h1>
    	</div>
    	<div id="nav"><br>
    		 <a href="user"> 查 询</a><br> <br>
    		 <a href="add"> 新 增</a><br>
    	</div>
    
    	<div id="section">
    	<br>	<br>	<br>	<br>	<br> 	<br>	<br>
    	<h2>人生若只如初见,何事秋风悲画扇</h2>						
    	</div>
    	<div id="footer">Good luck !</div>
    </body>
    </html>
    

    2 add.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    	pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    .tab {
    	border-top: 1px solid #000;
    	border-left: 1px solid #000;
    	text-align: center
    }
    
    .tab td {
    	border-bottom: 1px solid #000;
    	border-right: 1px solid #000;
    }
    
    #header {
    	background-color: #5CADAD;
    	color: white;
    	text-align: center;
    	padding: 5px;
    }
    
    #nav {
    	line-height: 30px;
    	background-color: #B3D9D9;
    	height: 500px;
    	width: 100px;
    	float: left;
    	padding: 5px;
    	text-align: center;
    }
    
    #section {
    	height: 500px;
    	width: 1212px;
        background-color: #F5F5F5;
    	text-align: center;
    	float: left;
    	padding: 5px;
    }
    
    #footer {
    	background-color: #B3D9D9;
    	color: white;
    	clear: both;
    	text-align: center;
    	padding: 5px;
    }
    </style>
    </head>
    
    <body>
    
    	<div id="header">
    		<h1>Welcome to my world! </h1>
    	</div>
    
    	<div id="nav"><br>
    	</div>
    
    	<div id="section">
    		<form action="addUser" method="post">
    			<table class="tab" cellspacing="0" cellpadding="0" width="600" height="200">
    				<tr>
    					<td width="80px" height="30px">学号:</td>
    					<td width="80px" height="30px"><input type="text"
    						name="userId" value="${user.userId}" /></td>
    				</tr>
    				<tr>
    					<td width="80px" height="30px">编号:</td>
    					<td width="80px" height="30px"><input type="text"
    						name="userCode" value="${user.userCode}" /></td>
    				</tr>
    				<tr>
    					<td width="80px" height="30px">姓名:</td>
    					<td width="80px" height="30px"><input type="text"
    						name="userName" value="${user.userName}" /></td>
    				</tr>
    				<tr>
    					<td></td>
    					<td><input type="submit" value="增加"> <a
    						href="javascript:history.go(-1);" class="FunctionButton"><input
    							type="button" value="返回"></a></td>
    				</tr>
    			</table>
    	</form>
    	</div>
    
    	<div id="footer">Good luck !</div>
    
    </body>
    </html>
    

    3 update.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    	pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    .tab {
    	border-top: 1px solid #000;
    	border-left: 1px solid #000;
    	text-align: center
    }
    
    .tab td {
    	border-bottom: 1px solid #000;
    	border-right: 1px solid #000;
    }
    
    #header {
    	background-color: #5CADAD;
    	color: white;
    	text-align: center;
    	padding: 5px;
    }
    
    #nav {
    	line-height: 30px;
    	background-color: #B3D9D9;
    	height: 500px;
    	width: 100px;
    	float: left;
    	padding: 5px;
    	text-align: center;
    }
    
    #section {
    	height: 500px;
    	width: 1212px;
        background-color: #F5F5F5;
    	text-align: center;
    	float: left;
    	padding: 5px;
    }
    
    #footer {
    	background-color: #B3D9D9;
    	color: white;
    	clear: both;
    	text-align: center;
    	padding: 5px;
    }
    </style>
    </head>
    
    <body>
    
    	<div id="header">
    		<h1>Welcome to my world! </h1>
    	</div>
    
    	<div id="nav"><br>
    	</div>
    
    	<div id="section">
    		<form action="updateStudentById" method="post">
    			<table class="tab" cellspacing="0" cellpadding="0" width="600" height="200">
    				<tr>
    					<td width="80px" height="30px">学号:</td>
    					<td width="180px" height="30px"><input type="text"
    						width="180px" height="30px" name="userId" value="${user.userId}" /></td>
    				</tr>
    				<tr>
    					<td width="80px" height="30px">编号:</td>
    					<td width="180px" height="30px"><input type="text"
    						width="180px" height="30px" name="userCode"
    						value="${user.userCode}" /></td>
    				</tr>
    				<tr>
    					<td width="80px" height="30px">姓名:</td>
    					<td width="180px" height="30px"><input type="text"
    						width="180px" height="30px" name="userName"
    						value="${user.userName}" /></td>
    				</tr>
    				<tr>
    					<td ></td>
    					<td><input type="submit" value="修改"
    						class="FunctionButtonInput"> <a
    						href="javascript:history.go(-1);" class="FunctionButton"><input
    							type="button" value="返回"></a></td>
    				</tr>
    			</table>
    		<from/>
    	</div>
    
    	<div id="footer">Good luck !</div>
    
    </body>
    </html>
    

    4 selectOne.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <meta charset="UTF-8">
    
    <title>Insert title here</title>
    <style type="text/css">
      .tab{border-top:1px solid #000;border-left:1px solid #000;text-align:center}
      .tab td{border-bottom:1px solid #000;border-right:1px solid #000;}
    </style>
    <script>
    	function users(){
    		alter("123")
    	}
    </script>
    </head>
    <body>
    <center>
            <table class="tab" cellspacing="0" cellpadding="0" width="600" height="200">
                <tr align="center" valign="middle" >
    				<td>学号</td>
    				<td>编号</td>
    				<td>ˆ姓名</td>
    				<td>操作</td>
    			</tr>
    			<c:forEach items="${user}" var="st">
    				<tr align="center" valign="middle">
    					<td>${st.userId}</td>
    					<td>${st.userCode}</td>
    					<td>${st.userName}</td>
    					<td >
                        	  <a href="deleteStudentById?id=${st.userId}">删除</a>
                       		 <a href="selectOneUserById?id=${st.userId}">修改</a>
                       		 <a href="javascript:history.go(-1);" class="FunctionButton"><input type="button" value="返回"></a>
                        </td>
    				</tr>
    			</c:forEach>
    	</table>
    </center>
    </body>
    </html>
    

    5 user.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    	pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    .tab {
    	border-top: 1px solid #000;
    	border-left: 1px solid #000;
    	text-align: center
    }
    
    .tab td {
    	border-bottom: 1px solid #000;
    	border-right: 1px solid #000;
    }
    
    #header {
    	background-color: #5CADAD;
    	color: white;
    	text-align: center;
    	padding: 5px;
    }
    
    #nav {
    	line-height: 30px;
    	background-color: #B3D9D9;
    	height: 500px;
    	width: 100px;
    	float: left;
    	padding: 5px;
    	text-align: center;
    }
    #nav1 {
    	background-color: #B3D9D9;
    	color: white;
    	clear: both;
    	text-align: center;
    	padding: 5px;
    }
    
    #section {
    	height: 500px;
    	width: 1212px;
        background-color: #F5F5F5;
    	text-align: center;
    	float: left;
    	padding: 5px;
    }
    
    #footer {
    	background-color: #B3D9D9;
    	color: white;
    	clear: both;
    	text-align: center;
    	padding: 5px;
    }
    </style>
    </head>
    
    <body>
    
    	<div id="header">
    		<h1>Welcome to my world! </h1>
    	</div>
    
    	<div id="nav"><br>
    	<a href="index" class="FunctionButton">返回</a><br>
    	<a href="add"> 新增</a>
    	</div>
    
    	<div id="section">
    		<table class="tab" cellspacing="0" cellpadding="0" width="600"
    			height="200">
    			<tr align="center" valign="middle">
    				<td>学号</td>
    				<td>编号</td>
    				<td>姓名</td>
    				<td>操作</td>
    			</tr>
    
    			<c:forEach items="${user}" var="st">
    				<tr align="center" valign="middle">
    					<td>${st.userId}</td>
    					<td>${st.userCode}</td>
    					<td>${st.userName}</td>
    					<td><a href="deleteStudentById?id=${st.userId}">删除 </a> <a
    						href="selectOneUserById?id=${st.userId}">修改</a> <a
    						href="selectOneUserById?id=${st.userId}">查询</a></td>
    				</tr>
    			</c:forEach>
    
    		</table>
    	</div>
    	<div id="footer">Good luck !</div>
    
    </body>
    </html>
    

    (10)、pom.xml

    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.xxx.ssm</groupId>
      <artifactId>demoWeb</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>demoWeb Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
    	<parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.5.RELEASE</version>
    	</parent>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      <!-- Spring Boot web依赖 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
    		<!-- Spring Boot 热部署 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-devtools</artifactId>
    		</dependency>
    		<!-- tomcat的支持. -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-tomcat</artifactId>
    			<scope>provided</scope>
    		</dependency>
    		<!-- 访问JSP页面必须配置 -->
    		<dependency>
    			<groupId>org.apache.tomcat.embed</groupId>
    			<artifactId>tomcat-embed-jasper</artifactId>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    		    <groupId>mysql</groupId>
    		    <artifactId>mysql-connector-java</artifactId>
    		</dependency>
         	 <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
             </dependency>
          	<dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <!-- web开发包:包含Tomcat和Springmvc -->
            
              <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.2</version>
            </dependency>
           
    		<dependency>           
    			<groupId>tk.mybatis</groupId>            
    			<artifactId>mapper-spring-boot-starter</artifactId>            
    			<version>2.0.0</version>        
    		</dependency>
    		<!-- thymeleaf -->
    		<!-- <dependency>
    		    <groupId>org.springframework.boot</groupId>
    		    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    		</dependency> -->
    		<dependency> 
    			<groupId>net.sourceforge.nekohtml</groupId> 
    			<artifactId>nekohtml</artifactId> 
    		</dependency> 
    		<!--帮助页面-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.6.1</version>
            </dependency>
     
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.6.1</version>
            </dependency>
            
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                 <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId> 
                <scope>provided</scope>
            </dependency>
             <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jsp-api</artifactId>
            </dependency>
    		
    	</dependencies>
    	<build>
    		<plugins>
           		  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <configuration>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
              <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
        	</plugins>
    	<resources>
    		<resource>
    			<directory>src/main/java</directory>
    			<includes>
    				<include>**/*.yml</include>
    				<include>**/*.properties</include>
    				<include>**/*.xml</include>
    			</includes>
    			<filtering>false</filtering>
    		</resource>
    		<resource>
    			<directory>src/main/resources</directory>
    			<includes>
    				<include>**/*.yml</include>
    				<include>**/*.properties</include>
    				<include>**/*.xml</include>
    			</includes>
    			<filtering>false</filtering>
    		</resource>
    	</resources>
    	</build>
    </project>
    
    
    

    3、访问地址和结果展示

    (1)请求地址
    http://localhost:8081/test/index
    (2)、结果展示
    在这里插入图片描述

    展开全文
  • 通过Java,jdbc,mysql,实现后端对数据库的操作
  • JSP+JDBC实现增删改查

    万次阅读 多人点赞 2018-01-16 09:27:31
    需求:创建一张老师表,使用jdbc+jsp实现增删改查 1、创建数据库表 2、创建一个web项目 3、代码编写 实体类: public class Teacher { private Integer ...
  • jsp商品增删改查

    2018-07-09 16:31:16
    jsp实现商品的增删改查 案例 供新手浏览 学习
  • Servlet+JSP实现员工增删改查-附件资源
  • javaweb开发,连接Oracle数据库,通过网页注册,登录后对数据库中的用户表进行增删查。实现了登录、注册、增删改查等功能。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,808
精华内容 723
关键字:

jsp实现增删改查