用liferay实现的增删改查例子-book管理系统

liferay 这个框架是一个开源的项目,大家可以修改源代码,来实现自己的需求。但是关于liferay的开发资料中文的很少关于liferay的基础知识,大家可以百度学习一下,再来看下边的例子

首先需要搭建环境,搭建环境百度一大堆,在这里不废话,直接上代码,

开发的步骤1:首先配置需要的配置的文件

<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.1.0//EN" "http://www.liferay.com/dtd/liferay-display_6_1_0.dtd">

<display>
<category name="category.ebizwindow.book">//在这个地方大家需要修改一下名字,不然的话在liferay的界面上不会显示出来你写的项目
<portlet id="BookSystem" />
</category>
</display>

2个配置的文件是

<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
<portlet>
<portlet-name>BookSystem</portlet-name>
<display-name>BookSystem</display-name>
<portlet-class>com.ebizwindow.exceed.portlet.BookPortlet</portlet-class>//在这地方修改你要写的portlet的名字,默认生成的是JSPPortlet
<init-param>
<name>view-jsp</name>
<value>/jsp/book/mybook-list.jsp</value>//这个页面是你要访问的第一个页面,在这个页面是通过doView方法找到的页面。
</init-param>
<init-param>
<name>edit-jsp</name>
<value>/jsp/edit.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<supported-locale>zh_CN</supported-locale>
<resource-bundle>content.Language-ext</resource-bundle>
<portlet-info>
<title>BookSystem</title>
<short-title>BookSystem</short-title>
<keywords>BookSystem</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>

3.是service.xml的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 5.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_5_2_0.dtd">

<service-builder package-path="com.ebizwindow.exceed">
<namespace>BookSystem</namespace>

<entity name="Book" local-service="true" remote-service="false">//remote-service="false"这个设置为false的就是自动生成的时候不是生成一些方法, local-service="true"这个设置为true就会在项目中生成一些程序员要调用的方法。

<!-- company 公司的id -->
<column name="companyId" type="long" />//这个companyId就是自动有的这个不需要修改,就是公司的id

<!-- PK fields -->
<column name="bookId" type="long" primary="true" />//这个就是你的实体的id

<!-- Other fields 实体的属性-->
<column name="bookName" type="String" />
<column name="bookAuthor" type="String" />
<column name="bookAddress" type="String" />
<column name="bookPrice" type="double" />
<column name="bookDate" type="Date" />

<!-- Order 检索出来的数据按照name排序-->
<order by="asc">
<order-column name="bookName" />
</order>

<!-- Finder methods -->
<finder name="companyId" return-type="Collection">//对应自动生成的方法是getCompanyId(long companyId)。顾名思义就是按照公司的id检索所有的数据
<finder-column name="companyId" />
</finder>
<!-- 这个是根据用户的名字返回图书 -->
<finder return-type="Collection" name="bookName">//对应生成的方法是getBookName(String bookName)

<finder-column name="bookName" />

</finder>

<!-- 根据作者来查看图书 -->
<finder return-type="Collection" name="bookAuthor">//对应生成的方法是getBookAuthor(String bookAuthor)

<finder-column name="bookAuthor" />

</finder>

</entity>

</service-builder>

需要注意:根据实体的主键来检索一条数据,这个方法是不需要配置,默认会生成.

好吧,罗嗦了一大会,配置文件就搞定了,点击builder.xml,点击builder-service就会自动生成方法和实体,程序员只需要写自己的逻辑的代码就行了。

下面开始写portlet,这个portlet跟大家学的servlet有很大相似,但是也有不同,自己百度查查就知道。

package com.ebizwindow.exceed.portlet;

import com.ebizwindow.exceed.model.Book;
import com.ebizwindow.exceed.service.BookLocalServiceUtil;
import com.liferay.compat.portal.util.PortalUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portlet.PortletURLFactoryUtil;

import java.io.IOException;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletModeException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowStateException;

public class BookPortlet extends GenericPortlet {

	private final static String FORWARD = "forward";

	private final static String OPERATION = "operation";

	public void init() throws PortletException {
		editJSP = getInitParameter("edit-jsp");
		helpJSP = getInitParameter("help-jsp");
		viewJSP = getInitParameter("view-jsp");
	}

	public void doList(PortletRequest portletRequest){

		long companyId = PortalUtil.getCompanyId(portletRequest);

		_log.info(companyId+"ggggggggg$$$$$$$$$$$$$$$$$$$$");
		try {
			//得到数据库中所有的书籍
			List<Book> books = BookLocalServiceUtil.searchByCompanyId(companyId);

			_log.info(StringUtil.merge(books)+"abcdef=============================");

			//然后把书发送给jsp.首先把图书存到响应中
			portletRequest.setAttribute("books", books);

		} catch (SystemException e) {
			e.printStackTrace();
		}

	}

	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

		String jspPage = renderRequest.getParameter(FORWARD);
		if (jspPage == null) {
			this.doList(renderRequest);
		}
		jspPage = jspPage == null ? this.viewJSP : jspPage;
		include(jspPage, renderRequest, renderResponse);

	}

	public void doEdit(RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

		if (renderRequest.getPreferences() == null) {
			super.doEdit(renderRequest, renderResponse);
		} else {
			include(editJSP, renderRequest, renderResponse);
		}
	}

	public void doHelp(RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

		include(helpJSP, renderRequest, renderResponse);
	}

	public static PortletURL getPortletURL(ActionRequest actionRequest) throws PortalException, SystemException {
		long groupId = PortalUtil.getScopeGroupId(actionRequest);
		String portletId = PortalUtil.getPortletId(actionRequest);
		long plid = PortalUtil.getPlidFromPortletId(groupId, portletId);
		PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
				portletId, plid, PortletRequest.ACTION_PHASE);
		try {
			redirectURL.setPortletMode(actionRequest.getPortletMode());
			redirectURL.setWindowState(actionRequest.getWindowState());
		} catch (PortletModeException e) {
			_log.error(e);
		} catch (WindowStateException e) {
			_log.error(e);
		}
		return redirectURL;
	}

	public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
		throws IOException, PortletException {

		//得到操作的名称
		String actionName = ParamUtil.getString(actionRequest, OPERATION);

		if (actionName != null) {
			String forward = null;
			_log.info(ActionRequest.ACTION_NAME + " = " + actionName);

			if (actionName.equals("list")) {
				//首先执行这个请求的时候,就找到数据要去的页面
				//1:首先从数据库中选出来所有的数据,根据公司的id就行了
				//首先获取id
				this.doList(actionRequest);

				forward = "/jsp/book/mybook-list.jsp";
			} else if(actionName.equals("details")) {
				// 查看书的详细的信息1:首先获得前台界面传过来的id
				long bookId = ParamUtil.getLong(actionRequest, "bookId",0L);

				//在调用本地方法的实现的类
				Book book = null;
				try {
					 book = BookLocalServiceUtil.getBook(bookId);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//把这本书发送给界面就可以
				actionRequest.setAttribute("book", book);

				forward = "/jsp/book/mybook-details.jsp";
			} else if (actionName.equals("load")) {
				//如果的到的参数load的话就是要跳转的页面

				_log.info("----------------------------------------------"+actionName+"-------success");
				forward = "/jsp/book/mybook-add.jsp";

			}

			else if(actionName.equals("add")) {
				_log.info("@@@@@@@@@@@@@@@@@@@@@@@");
				//首先获取信息页面传过来的信息
				String bookName = ParamUtil.getString(actionRequest, "bookName",StringPool.BLANK);
				String bookAuthor =ParamUtil.getString(actionRequest, "bookAuthor",StringPool.BLANK);
				String bookAddress = ParamUtil.getString(actionRequest, "bookAddress",StringPool.BLANK);
				DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
				Date bookDate = (Date) ParamUtil.getDate(actionRequest, "bookDate", dateFormat);
				double bookPrice = ParamUtil.getDouble(actionRequest, "bookPrice",0.0);

				long companyId = PortalUtil.getCompanyId(actionRequest);
				_log.info(bookName+"--"+bookAuthor+"--"+bookAddress+"--"+bookPrice+"--"+bookDate);
				//添加图书,添加图书的时候你需要考虑id
				long bookId = 0L;
				try {
					bookId = CounterLocalServiceUtil.increment(Book.class.getName());
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//创建一个book的引用
				Book book = BookLocalServiceUtil.createBook(bookId);

				book.setBookAddress(bookAddress);
				book.setBookAuthor(bookAuthor);
				book.setBookDate(bookDate);
				book.setBookName(bookName);
				book.setBookPrice(bookPrice);
				book.setCompanyId(companyId);
				//调用添加的方法添加到数据库
				try {
					BookLocalServiceUtil.addBook(book);
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				this.doList(actionRequest);
				//数据添加到数据库中之后就到list的界面上

				//重定向
				PortletURL redirect = null;
				try {
					redirect = getPortletURL(actionRequest);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				redirect.setPortletMode(PortletMode.VIEW);
				actionResponse.sendRedirect(redirect.toString());

			}else if (actionName.equals("edit")){
				//首先获取用户要修改的id,然后根据id找到信息
				long bookId = ParamUtil.getLong(actionRequest, "bookId",0L);

				Book book = null;
				try {
					 book = BookLocalServiceUtil.getBook(bookId);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//把这本书发送给界面就可以
				actionRequest.setAttribute("book", book);

				forward = "/jsp/book/mybook-edit.jsp";
			} 

			else if(actionName.equals("editTrue")) {//得到的方法是修改
				//首先获得要编辑图书的id
				long bookId = ParamUtil.getLong(actionRequest, "bookId",0L);
				//根据id找到图书
				Book book = null;
				try {
					 book= BookLocalServiceUtil.getBook(bookId);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//获得提交修改后的数据的参数
				String bookName = ParamUtil.getString(actionRequest, "bookName",StringPool.BLANK);
				String bookAuthor =ParamUtil.getString(actionRequest, "bookAuthor",StringPool.BLANK);
				String bookAddress = ParamUtil.getString(actionRequest, "bookAddress",StringPool.BLANK);
				DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
				Date bookDate = (Date) ParamUtil.getDate(actionRequest, "bookDate", dateFormat);
				double bookPrice = ParamUtil.getDouble(actionRequest, "bookPrice",0.0);
				book.setBookAddress(bookAddress);
				book.setBookAuthor(bookAuthor);
				book.setBookDate(bookDate);
				book.setBookName(bookName);
				book.setBookPrice(bookPrice);
				//调用数据库中修改的方法
				try {
					BookLocalServiceUtil.updateBook(book);
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				PortletURL redirect = null;
				try {
					redirect = getPortletURL(actionRequest);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				redirect.setPortletMode(PortletMode.VIEW);
				actionResponse.sendRedirect(redirect.toString());

			} else if (actionName.equals("delete")){
				//删除的方法.首先获得要删除的数据的id
				long bookId = ParamUtil.getLong(actionRequest, "bookId",0L);
				//调用数据库删除的方法
				try {
					BookLocalServiceUtil.deleteBook(bookId);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				PortletURL redirect = null;
				try {
					redirect = getPortletURL(actionRequest);
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SystemException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				redirect.setPortletMode(PortletMode.VIEW);
				actionResponse.sendRedirect(redirect.toString());

			}else{
				forward = this.helpJSP;
			}

			_log.info(FORWARD + " = " + forward);

			if(forward != null){
				actionResponse.setRenderParameter(FORWARD, forward);
			}

		}
	}

	public void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

		String jspPage = renderRequest.getParameter(FORWARD);

		if (jspPage != null) {
			include(jspPage, renderRequest, renderResponse);
		} else {
			super.doDispatch(renderRequest, renderResponse);
		}
	}

	protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

		PortletRequestDispatcher portletRequestDispatcher =
			getPortletContext().getRequestDispatcher(path);

		if (portletRequestDispatcher == null) {
			_log.error(path + " is not a valid include");
		} else {
			portletRequestDispatcher.include(renderRequest, renderResponse);
		}
	}

	protected String editJSP;
	protected String helpJSP;
	protected String viewJSP;

	private static Log _log = LogFactoryUtil.getLog(BookPortlet.class);

}

  界面代码:

mybook-list.jsp界面

<%@ page language="java" import="java.util.*" pageEncoding="Utf-8"%>
<%@page import="javax.portlet.PortletPreferences"%>
<!-- 引入init.jsp -->
<%@ include file="/init.jsp"%>
<!-- 使用portlet标签 来设计页面-->
<!-- 首先定义portlet提交的路径
<portlet:actionURL var="searchURL">
	<portlet:param name="operation" value="example.list" />
</portlet:actionURL>
 -->
<portlet:actionURL var="listURL">

	<portlet:param name="operation" value="list" />

</portlet:actionURL>

<!-- form表单的内容 -->
<form action="<%=listURL %>" method="post">

	<fieldset>

		<table>
			<tr>
				<legend>图书列表</legend>
				<th>图书名称</th>
				<th>图书作者</th>
				<th>图书出版社</th>
				<th>图书出版日期</th>
				<th>图书价格</th>
			</tr>

			<%
				//首先获取后台发过来的数据List<Orenge> results = (List<Orenge>)renderRequest.getAttribute("results");
				List<Book> books = (List<Book>)renderRequest.getAttribute("books");

				if (books.size()>0 || books != null) {
					for (Book book:books) {%>

				<td>
					<portlet:actionURL var="detailBookURL" windowState="<%=LiferayWindowState.EXCLUSIVE.toString() %>">
							<portlet:param name="operation" value="details" />
							<portlet:param name="bookId" value=‘<%=String.valueOf(book.getBookId())%>‘ />
						</portlet:actionURL>
						<a href="javascript:showOrenge(‘<%=detailBookURL %>‘, ‘book‘)"><%=book.getBookName() %></a>
				</td>

				<td>
					<%=book.getBookAuthor() %>

				</td>

				<td>
					<%=book.getBookAddress() %>

				</td>

				<td>
					<%=book.getBookDate() %>

				</td>

				<td>
					<%=book.getBookPrice() %>

				</td>

				<td>
						<liferay-ui:icon-menu>
							<portlet:actionURL var="editBookURL">
								<portlet:param name="operation" value="edit" />
								<portlet:param name="bookId" value=‘<%=String.valueOf(book.getBookId())%>‘ />
							</portlet:actionURL>
							<liferay-ui:icon image="edit" url="<%=editBookURL %>" message="edit"/>

							<portlet:actionURL var="deleteBookURL">
								<portlet:param name="operation" value="delete"/>
								<portlet:param name="action" value="delete"/>
								<portlet:param name="bookId" value=‘<%=String.valueOf(book.getBookId())%>‘ />
							</portlet:actionURL>
							<liferay-ui:icon-delete url="<%=deleteBookURL %>" />
						</liferay-ui:icon-menu>
					</td>		

					<% }

				}

			%>

		</table>

	</fieldset>

	<div>
		<portlet:actionURL var="addBookURL">
			<!-- 找到添加的页面 -->
			<portlet:param name="operation" value="load" />

		</portlet:actionURL>
		<input type="button" value="添加" onclick="javascript:location.href=‘<%=addBookURL %>‘">

	</div>

</form>

  2.mybook-add.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/init.jsp" %>
<portlet:actionURL var="addBookURL">
	<!-- 执行add的操作 -->
	<portlet:param name="operation" value="add" />

</portlet:actionURL>

  <form action="<%=addBookURL %>" method="post">
		图书名称:<input type="text" name="bookName" /></br>
		图书作者:<input type="text" name="bookAuthor"/></br>
		出版社:<input type="text" name="bookAddress"/></br>
		出版日期:<input type="text" name="bookDate"/></br>
                           图书价格:<input type="text" name="bookPrice"/></br>

		<input type="submit" value="提交"/>
		<input type="reset" value="重置"/>
  </form>

  3.mybook-edit.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/init.jsp" %>

<%
	//得到要修改的图书
	Book book = (Book)renderRequest.getAttribute("book");

%>

<portlet:actionURL var="editBookURL">
	<portlet:param name="operation" value="editTrue" />
	<portlet:param name="bookId" value=‘<%=book != null ? String.valueOf(book.getBookId()) : "0" %>‘ />
</portlet:actionURL>

  <form action="<%=editBookURL %>" method="post">
		图书名称:<input type="text" name="bookName" value=‘<%=book != null ? String.valueOf(book.getBookName()):"" %>‘/></br>
		图书作者:<input type="text" name="bookAuthor" value=‘<%=book != null ? String.valueOf(book.getBookAuthor()) :"" %>‘/></br>
		出版社:<input type="text" name="bookAddress" value=‘<%=book != null ? String.valueOf(book.getBookAddress()):""  %>‘/></br>
		出版日期:<input type="text" name="bookDate" value=‘<%=book != null   ? String.valueOf(book.getBookDate()):""  %>‘/></br>
                           图书价格:<input type="text" name="bookPrice" value=‘<%=book != null  ? String.valueOf(book.getBookPrice()):""  %>‘/></br>

		<input type="submit" value="提交"/>
		<input type="reset" value="重置"/>
  </form>

  4.mybook-detail.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!-- 引入init.jsp -->
<%@ include file="/init.jsp"%>
<%
	Book book = (Book)renderRequest.getAttribute("book");
%>

<style>
	#bookcontent{

	}

</style>

<div id = "bookcontent">
<table>
	<tr>
		<td>图书名称</td>
		<td>图书作者</td>
		<td>出版地址</td>
		<td>出版日期</td>
		<td>图书价格</td>
	</tr>

	<tr>
		<td>
			<%=book.getBookName() %>
		</td>

		<td>
			<%=book.getBookAuthor() %>
		</td>

		<td>
			<%=book.getBookAddress() %>
		</td>

		<td>
			<%=book.getBookDate() %>
		</td>

		<td>
			<%=book.getBookPrice() %>
		</td>

	</tr>

</table>
</div>

  终于结束了点击运行服务器,就可以实现了,下面动手试试吧!

时间: 2024-11-06 09:46:42

用liferay实现的增删改查例子-book管理系统的相关文章

spring boot2+jpa+thymeleaf增删改查例子

参考这遍文章http://www.ityouknow.com/springboot/2017/09/23/spring-boot-jpa-thymeleaf-curd.html做了一个例子,稍微不同之处,原文是spring boot.mysql,这里改成了spring boot 2.Oracle. 一.pom.xml引入相关模块web.jpa.thymeleaf.oracle: <dependency> <groupId>org.springframework.boot</g

javascript操作xml(增删改查)例子代码

包括了stu.hta(是HTML应用程序);      stu.xml 注意下面的HTML代码必须保存为后缀名为hta否则当对XML文件进行操作(增删改)的时候就会提示没有权限!! 文件stu.hta代码如下: 代码 <html><head><title> 数据岛的显示 </title><style type="text/css">#findPanel{ position:absolute; width:220px; bord

使用mybatis框架的一个简单的用户商品的增删改查例子

---恢复内容开始--- 这个例子的实现过程:用户登录----->servlet验证用户是否存在----->显示商品信息----->可以进行商品的删除.修改.添加功能(商品信息是分页显示的) 例子很简单,但是基本的mybatis框架一个也差不多是这样的 数据库表格如下 项目的结构 1.src目录下的mybatis文件和外部源文件 jdbc.properties jdbc.driver=oracle.jdbc.driver.OracleDriver jdbc.url=jdbc:oracle

JSP的一个增删改查例子和总结

总结的几点: 1.在jsp中注意<%! %>声明代码块中的变量只会在项目开始的时候第一次运行jsp的时候执行一遍,有点类似于java类中的static代码块,所以如果是会改变的值不应该声明在这里面.而是卸载<%%>代码块中 2.使用js中的location.href有时候就是无法生效,也就是无法跳转到你想要的页面.你可以在location.href语句后面加上 event.returnValue=false即可 3.进行编辑一条信息或者删除信息的时候id字段可以使用隐藏域或者直接使

数据库增删改查例子

表名: person字段: id, name, age1 张三 202 李四 223 王五 23 查询: select id,name,age from person;删除: delete from person where id=1 (删除ID=1的那条数据,)delete from person (删除person表中的所有数据);修改: update person set name="刘德华" where id=2; (就会李四的名字改成刘德华);增加: insert into

Redis之五种数据类型的简单增删改查

开心一笑 乌龟受伤.让蜗牛去买药.过了2个小时.蜗牛还没回来.乌龟急了骂道:他妈的再不回来老子就死了!这时门外传来了蜗牛的声音:你他妈再说老子不去了! 提出问题 Redis五种数据类型的简单增删改查命令??? 解决问题 假设你已经安装Redis服务器: 假设你已经打开Redis cli命令行工具: 假设你对Redis有所了解: Redis简单增删改查例子 例一:字符串的增删改查 #增加一个key为ay_key的值 127.0.0.1:6379> set ay_key "ay" O

Hibernate的四种典型例子(增删改查)

Hibernate的四种典型例子(增删改查)  //查询  // Session session=HibernateSessionFactory.getSession();  // session.beginTransaction();  // Query q=session.createQuery("from Info where id=:id");  // q.setInteger("id", 1);  // List l=q.list();  // Info

前端的CRUD增删改查的小例子

前端的CRUD增删改查的小例子 1.效果演示 2.相关代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin: 0; padding: 0; } .box{ width: 300px; margin: 0 auto; } ul{

Servlet中请给出一个Cookie的增删改查的例子。

2.Servlet与Cookie:(视频下载) (全部书籍) 马 克-to-win:Cookie有点像Session.Session是把键值对存在服务器端,一个Servlet存值 ,另外一个Servlet可以取值.Cookie也是以键值对的形式用于读取,不过是保存在客户端 浏览器的某个文本里面.取时,也要从这台机器的这个浏览器上去取.像Session一样,你 也可以设置过期时间,比如“一年”.和Session不同的是:用户可以把自己浏览器的Cookie工作系统关掉.这就是Cookie不如Sess