- 浏览: 6071 次
- 性别:
- 来自: 深圳
最新评论
文章列表
一、创建实体类
package com.wr.hibernate.entity;
import java.util.HashSet;
import java.util.Set;
public class Person {
private int id;
private String name;
private Set<Role> roles = new HashSet<Role>();
public int getId() {
return id;
}
public void setId(int id) { ...
一、创建实体类
package com.wr.hibernate.entity;
public class Department {
private int deptId;
private String deptName;
private Manager mgr;
public int getDeptId() {
return deptId;
}
public Manager getMgr() {
return mgr;
}
public void setMgr(Manager mgr) {
this.mgr = ...
一、创建实体类
package com.wr.hibernate.entity;
import java.util.HashSet;
import java.util.Set;
public class Custom {
private int customId;
private String customName;
private Set<Order> orders = new HashSet<Order>();
public Set<Order> getOrders() {
return orders;
...
一、创建是实体类
package com.wr.hibernate.entity;
public class Custom {
private int customId;
private String customName;
public int getCustomId() {
return customId;
}
public void setCustomId(int customId) {
this.customId = customId;
}
public String getCustomName() {
re ...
一、session的fresh和refresh方法
fresh: 刷新session缓存, 把session中的数据同步到数据库. 事务在提交的时候, 会先默认的先调用session的 fresh方法.
refresh: 让session中缓存数据和数据库保持一致.
二、save和persist
save和persist都用于持久化对象, 但是设置主键生成方式后, 保存的POJO还是有ID的话, save方法将忽略id,
而persist将抛出异常.
一、加入相关jar包
maven方式: 加入hibernate-core依赖即可
二、在src下加入hibernate.cfg.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourc ...
1.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/ja ...
SpringMVC入门程序
- 博客分类:
- SpringMVC
1.加入jar包
2.配置SpringMVC的Servlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ht ...
一、Cookie介绍
cookie: 为保持会话状态, 存储在客户端的数据.
//创建一个cookie
Cookie cookie = new Cookie(name , value);
//将cookie传入客户端
response.addCookie(cookie );
客户端每次访问会回传cookie, 服务器端遍历cookie代码
Cookie[] cookies = request.getCookies();
if(null != cookies && cookies.length > ...
1.JSP页面写中文
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
保证contentType, pageEncoding和浏览器编码都是UTF-8则不会出现乱码
2.表单提交中文
<%
request.setCharacterEncoding("UTF-8");
%>
<%=
requ ...
1.JSP定义: java服务器页面,本质是一个由Servlet(由JSP引擎翻译生成).
2.JSP九大内置对象(JSP页面可以直接使用的对象)
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax ...