web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

  

sqlMapConfig.xml

<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings
cacheModelsEnabled ="true"
lazyLoadingEnabled="true"
enhancementEnabled="true"
errorTracingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="true"/>
<transactionManager type ="JDBC">
<dataSource type ="JNDI">
<property name ="DataSource" value ="java:comp/env/jdbc/emp" />
</dataSource>
</transactionManager>
<sqlMap resource ="com/struts2/entity/userMap.xml" />
<sqlMap resource ="com/struts2/entity/bookMap.xml" />
</sqlMapConfig >

  

bookMap.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="book"> <typeAlias alias="book" type="com.struts2.entity.Book"/>
<resultMap class="Book" id="bookResultMap">
<result property="bookId"/>
<result property="bname"/>
<result property="bprice"/>
<result property="bcount"/>
<result property="bds"/>
</resultMap> <select id="getBookList" resultMap="bookResultMap">
select bookId,bname,bprice,bcount,bds from(
select e.*,rownum rn from(
select * from Book where 1=1
<isNotNull property="bname" prepend="and">
bname like '%$bname$%'
</isNotNull>
<isNotEmpty property="bprice" prepend="and">
bprice <![CDATA[ <= $bprice$ ]]>
</isNotEmpty>
)e
)
where <![CDATA[ rn>=#startRow# and rn <=#endRow# ]]>
</select> <select id="getTotalCount" resultClass="java.lang.Integer">
select count(*)from Book where 1=1
<isNotNull property="bname" prepend="and">
bname like '%$bname$%'
</isNotNull>
<isNotEmpty property="bprice" prepend="and">
bprice <![CDATA[ <= $bprice$ ]]>
</isNotEmpty> </select> <insert id="addBook" parameterClass="Book">
insert into BOOK(bookId,bname,bprice,bcount,bds)values
(#bookId#,#bname#,#bprice#,#bcount#,#bds#)
</insert> <select id="getBookById" resultMap="bookResultMap">
select * from book where bookId =#bookId#
</select> <update id="updateBook" parameterClass="Book">
update book set bname=#bname#,bprice=#bprice#,bcount=#bcount#,bds=#bds#
where bookId=#bookId#
</update> <delete id="delBook" parameterClass="java.lang.Integer">
delete from book where bookId=#bookId#
</delete> <select id="getBookId" resultClass="java.lang.Integer">
select Seq_id.Nextval from dual
</select>
</sqlMap>

  userMap.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="user"> <typeAlias alias="User" type="com.struts2.entity.User"/>
<parameterMap id="userParameterMap" class="User" >
<parameter property="userid" />
<parameter property="username" />
<parameter property="userpassword" />
<parameter property="role" />
<parameter property="state" />
<parameter property="email" />
<parameter property="createdate" />
</parameterMap>
<resultMap id="userResultMap" class="User">
<result property="userid" column="USERID"/>
<result property="username" column="USERNAME"/>
<result property="userpassword" column="USERPASSWORD"/>
<result property="role" column="ROLE"/>
<result property="state" column="STATE"/>
<result property="email" column="EMAIL"/>
<result property="createdate" column="CREATEDATE"/>
</resultMap>
<select id="getUserByName" resultMap="userResultMap">
select * from User_New where username =#username#
</select>
</sqlMap>

sturt.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true"/> <package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" /> <global-results>
<result name="error">/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
</package>
<include file="user.xml"></include>
<include file="book.xml"></include>
</struts>

  

  book.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- <constant name="struts.enable.DynamicMethodInvocation" value="false" /> -->
<constant name="struts.devMode" value="true"/> <package name="book" namespace="/" extends="struts-default"> <action name="getBookList" class="com.struts2.action.BookAction">
<param name="list">list</param>
<result name="success">/jsp/list.jsp</result>
</action> <action name="addBook" class="com.struts2.action.BookAction"> <result name="success" >/jsp/list.jsp</result>
<result name="addError" >/jsp/error.jsp</result>
</action>
<action name="getbook" class="com.struts2.action.BookAction"> <result name="success" >/jsp/list.jsp</result>
<result name="updateError" >/jsp/error.jsp</result>
<result name="bookObj" >/jsp/updateBook.jsp</result>
</action> <action name="update" class="com.struts2.action.BookAction"> <result name="success" >/jsp/list.jsp</result>
<result name="updateError" >/jsp/error.jsp</result>
<result name="bookObj" >/jsp/updateBook.jsp</result>
</action>
<action name="delbook" class="com.struts2.action.BookAction"> <result name="success" >/jsp/list.jsp</result>
<result name="delError" >/jsp/error.jsp</result> </action> </package>
</struts>

  user.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- <constant name="struts.enable.DynamicMethodInvocation" value="false" /> -->
<constant name="struts.devMode" value="true"/> <package name="user" namespace="/" extends="struts-default">
<action name="login" class="com.struts2.action.UserAction">
<result name="success" type="redirectAction">getBookList</result>
<result name="input">/jsp/login.jsp</result>
</action>
</package> </struts>

 

 User.action

package com.struts2.action;

import com.opensymphony.xwork2.Action;
import com.struts2.service.UserService;
import com.struts2.service.impl.UserServiceImpl; public class UserAction implements Action { private String username;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
} UserService service = new UserServiceImpl() ; public String execute() throws Exception { boolean isLogin =service.isLogin(username, password);
if(isLogin){
return SUCCESS;
}else{
return INPUT;
} } }

  Book.acton

package com.struts2.action;

import java.util.ArrayList;
import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.StrutsStatics; import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.struts2.entity.Book;
import com.struts2.service.BookService;
import com.struts2.service.impl.BookServiceImpl; public class BookAction implements Action {
private Book book;
private String flag;
private Integer bookId;
private Integer totalCount;
private Integer totalPage; public Book getBook() {
return book;
} public void setBook(Book book) {
this.book = book;
} public Integer getTotalPage() {
return totalPage;
} public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
} public Integer getTotalCount() {
return totalCount;
} public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
} public Integer getBookId() {
return bookId;
} public void setBookId(Integer bookId) {
this.bookId = bookId;
} /* public String getBookId() {
return bookId;
} public void setBookId(String bookId) {
this.bookId = bookId;
}*/ public String getFlag() {
return flag;
} public void setFlag(String flag) {
this.flag = flag;
} public static final int PAGE_SIZE=5; public List<Book> getList() {
return list;
} public void setList(List<Book> list) {
this.list = list;
} private Integer pageIndex; public Integer getPageIndex() {
return pageIndex;
} public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
} BookService service = new BookServiceImpl();
List<Book>list = new ArrayList<Book>(); public String execute() throws Exception {
if("2".equals(flag)){ int bookId=service.getBookId();
book.setBookId(bookId);
boolean isAdd=service.addBook(book); book=null; if(!isAdd){
return "addError";
}
}else if("4".equals(flag)){ Book book2=service.getBookById(bookId); HttpServletRequest request=(HttpServletRequest)
ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
request.setAttribute("book", book2); return "bookObj";
}else if("5".equals(flag)){
boolean ismodify = service.modifyBook(book);
if(!ismodify){
return "updateError";
}
}else if("3".equals(flag)){
boolean isdel=service.delBook(bookId);
if(!isdel){
return "delError";
}
} if(pageIndex==null){ pageIndex=1;
} totalCount =service.getTotalCount(book);
list = service.getBookList(pageIndex, PAGE_SIZE,book);
totalPage = totalCount%PAGE_SIZE==0 ? (totalCount/PAGE_SIZE) : (totalCount/PAGE_SIZE+1);
return SUCCESS;
} }

  UserDao.java

package com.struts2.dao;

import com.struts2.entity.User;

	public interface UserDao {
public User getUserByName(String username); }

  

  UserDaoImpl.java

package com.struts2.dao.impl;

import java.sql.SQLException;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.struts2.dao.UserDao;
import com.struts2.entity.User;
import com.struts2.util.SqlMapClientUtil; public class UserDaoImpl implements UserDao{
SqlMapClient sqlMapClient = SqlMapClientUtil.getSqlMapClient();
User user=null;
public User getUserByName(String username){
try {
//("user.getUserByName")命名空间 id username
user = (User)sqlMapClient.queryForObject("user.getUserByName", username);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return user;
} }

  BookDao.java

package com.struts2.dao;

import java.util.List;
import com.struts2.entity.Book; public interface BookDao { public List<Book>getBookList(int pageIndex,int pageSize,Book book); public int getTotalCount(Book book); public Book getBookById(int bookId); public Book getBookById(String name); public boolean addBook(Book book); public boolean modifyBook(Book book); public boolean delBook(int bookId); public int getBookId();
}

   BookDaoImpl.java

package com.struts2.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.ibatis.sqlmap.client.SqlMapClient;
import com.struts2.dao.BookDao;
import com.struts2.entity.Book;
import com.struts2.util.SqlMapClientUtil; public class BookDaoImpl implements BookDao {
SqlMapClient sqlMapClient =SqlMapClientUtil.getSqlMapClient(); @Override
public List<Book> getBookList(int pageIndex, int pageSize,Book book) {
Map<String,Object> map = new HashMap<String,Object>();
List<Book>list = new ArrayList<Book>(); try {
int startRow=(pageIndex-1)*pageSize+1;
int endRow=pageIndex*pageSize;
map.put("startRow", startRow);
map.put("endRow", endRow);
if(book!=null){
map.put("bname",book.getBname()); map.put("bprice", book.getBprice()); }
list = sqlMapClient.queryForList("book.getBookList", map);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
} @Override
public int getTotalCount(Book book) {
Map<String,Object> map = new HashMap<String,Object>(); int count = 0;
try {
if(book!=null){
map.put("bname",book.getBname());
map.put("bprice", book.getBprice()); }
count =(Integer)sqlMapClient.queryForObject("book.getTotalCount",map);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return count;
} @Override
public Book getBookById(int bookId) { Book book=null;
try {
book = (Book)sqlMapClient.queryForObject("book.getBookById", bookId);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return book;
} public Book getBookById(String name) {
// TODO Auto-generated method stub
return null;
} @Override
public boolean addBook(Book book) {
SqlMapClient sqlMapClient=SqlMapClientUtil.getSqlMapClient();
try {
int count = sqlMapClient.update("book.addBook",book);
if(count>0){
return true;
}else{
return false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
} @Override
public boolean modifyBook(Book book) { try {
int count = sqlMapClient.update("book.updateBook",book);
if(count>0){
return true;
}else{
return false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return false;
} @Override
public boolean delBook(int bookId) {
int count;
try {
count = sqlMapClient.delete("book.delBook", bookId);
if(count>0){
return true;
}else{
return false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
public int getBookId(){
int bookId=0;
try {
bookId = (Integer)sqlMapClient.queryForObject("book.getBookId");
return bookId;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bookId;
} }

  

  User.java

package com.struts2.entity;

import java.util.Date;

public class User {
private int userid;
private String username;
private String userpassword;
private int role;
private int state;
private String email;
private Date createdate; public User(String username, String userpassword, int role, int state,
String email, Date createdate) {
super();
this.username = username;
this.userpassword = userpassword;
this.role = role;
this.state = state;
this.email = email;
this.createdate = createdate;
}
public User() {
super();
// TODO Auto-generated constructor stub
}
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
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 int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getCreatedate() {
return createdate;
}
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
}

  Book.java

package com.struts2.entity;

public class Book {
private int bookId;
private String bname;
private String bprice;
private int bcount;
private String bds; public Book( String bname, String bprice, int bcount, String bds) {
super(); this.bname = bname;
this.bprice = bprice;
this.bcount = bcount;
this.bds = bds;
} public Book() {
super();
// TODO Auto-generated constructor stub
} public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getBname() {
return bname;
}
public void setBname(String bname) {
this.bname = bname;
}
public String getBprice() {
return bprice;
}
public void setBprice(String bprice) {
this.bprice = bprice;
}
public int getBcount() {
return bcount;
}
public void setBcount(int bcount) {
this.bcount = bcount;
}
public String getBds() {
return bds;
}
public void setBds(String bds) {
this.bds = bds;
} }

  UserService.java

package com.struts2.service;

public interface UserService {

	public boolean isLogin(String username,String password);

}

  UserServiceImpl.java

package com.struts2.service.impl;

import com.struts2.dao.UserDao;
import com.struts2.dao.impl.UserDaoImpl;
import com.struts2.entity.User;
import com.struts2.service.UserService; public class UserServiceImpl implements UserService { public boolean isLogin(String username, String password) { UserDao userDao = new UserDaoImpl();
User user = userDao.getUserByName(username); if (user != null) { String pwd = user.getUserpassword(); if (pwd.equals(password)) {
return true;
}
return false;
} else {
return false;
}
}
}

  BookService.java

package com.struts2.service;

import java.util.List;
import com.struts2.entity.Book; public interface BookService { public List<Book>getBookList(int pageIndex,int pageSize,Book book); public int getTotalCount(Book book); public Book getBookById(int bookId); public Book getBookById(String name); public boolean addBook(Book book); public boolean modifyBook(Book book); public boolean delBook(int bookId); public int getBookId(); }

   BookServiceImpl.java

package com.struts2.service.impl;

import java.util.List;
import com.struts2.dao.BookDao;
import com.struts2.dao.impl.BookDaoImpl;
import com.struts2.entity.Book;
import com.struts2.service.BookService; public class BookServiceImpl implements BookService {
BookDao dao = new BookDaoImpl();
public List<Book> getBookList(int pageIndex, int pageSize,Book book) {
//
return dao.getBookList(pageIndex, pageSize, book);
} public int getTotalCount(Book book) { return dao.getTotalCount(book);
} public Book getBookById(int bookId) { return dao.getBookById(bookId); } public Book getBookById(String name) {
// TODO Auto-generated method stub
return null;
} public boolean addBook(Book book) { return dao.addBook(book);
} public boolean modifyBook(Book book) {
//
return dao.modifyBook(book);
} public boolean delBook(int bookId) {
//
return dao.delBook(bookId);
} @Override
public int getBookId() {
// TODO Auto-generated method stub
return dao.getBookId();
}
}

  SqlMapClientUtil.java

package com.struts2.util;

import java.io.IOException;
import java.io.Reader;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder; public class SqlMapClientUtil {
public static SqlMapClient getSqlMapClient() {
SqlMapClient sqlMapClient = null;
Reader reader = null; try {
reader = Resources.getResourceAsReader("sqlMapConfig.xml");
sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return sqlMapClient; }
}

  

JAVAWEB 一一 Sturts2+ibatis(框架,Sturts2,用action代替servlet)的更多相关文章

  1. JAVAWEB 一一 Spirng(框架,IOC控制反转,DI依赖注入)

    jar包 applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <bea ...

  2. JAVAWEB 一一 Hibernate(框架)

    实体类关联数据库字段,操作实体类,HQL语句对数据结构CRUD) 引入jar包 配置文件 hibernate.cfg.xml User.hbm.xml <?xml version="1 ...

  3. iBatis框架batch处理优化 (转)

    为什么要做batch处理        这个问题我就不解释了,因为我想你们肯定能比我解释的更好!如果你真的不知道,那就到Google上去搜索一下吧☻Oracle回滚段    这个问题偶也不很明白,只是 ...

  4. spring+struts2+ibatis 框架整合以及解析

    一. spring+struts2+ibatis 框架 搭建教程 参考:http://biancheng.dnbcw.net/linux/394565.html 二.分层 1.dao: 数据访问层(增 ...

  5. iBatis框架基本使用

    iBatis框架是Java持久层开发框架,说白了就是前人写了一部分代码(针对数据库操作),我们要做的就是再次开发,拿来框架直接使用. 我们自己开发时,dao层的sql语句都是写死在程序中的,如果查询条 ...

  6. iBatis框架简介

    一.为啥使用iBatis? 在 Hibernate.JPA 这样的一站式对象 / 关系映射(O/R Mapping)解决方案盛行之前,iBaits 基本是持久层框架的不二选择.即使在持久层框架层出不穷 ...

  7. 【转】深入分析 iBATIS 框架之系统架构与映射原理

    深入分析 iBATIS 框架之系统架构与映射原理 iBATIS 通过 SQL Map 将 Java 对象映射成 SQL 语句和将结果集再转化成 Java 对象,与其他 ORM 框架相比,既解决了 Ja ...

  8. 深入分析 iBATIS 框架之系统架构与映射原理--转载

    http://www.ibm.com/developerworks/cn/java/j-lo-ibatis-principle/ iBATIS 通过 SQL Map 将 Java 对象映射成 SQL ...

  9. Struts2框架学习(二) Action

    Struts2框架学习(二) Action Struts2框架中的Action类是一个单独的javabean对象.不像Struts1中还要去继承HttpServlet,耦合度减小了. 1,流程 拦截器 ...

  10. spring struts2 ibatis 框架结构图

    spring struts2 ibatis 框架结构图

随机推荐

  1. OpenJudge 兔子与樱花

    [题解] 求任意两点间的最短路径.此题数据量较小,用Floyd算法,时间复杂度为O(n^3). 参考https://blog.csdn.net/qq_34594236/article/details/ ...

  2. Linux下用node-inspector实现NodeJS远程调试开发

    1.首先安装 node-inspector npm install -g node-inspector -g表示全局安装,如果像我一样安装失败,再试几次,npm偶尔就会这样抽风... 这一步是关键的, ...

  3. celipse关联hadoop源码

    可以在这里下载hadoop的源码包 https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/ 我自己下载的是hadoop2.6.0的源码包 ...

  4. tomcat7.0安装笔记

    1. 解压,新增系统环境变量CATALINA_HOME,值为tomcat所在目录,如E: tomcat7.0 PS:安装JAVA时没有配置系统变量JAVA_HOME,导致报错无法启动tomcat,新建 ...

  5. css动画animation-keyframes

    随着css3的流行,现在很多可以使用css3实现的动画效果,基本上就选择css3实现,尤其是在移动端的(移动端对css3的支持度相对比较高,PC端有很多IE8及以下的浏览器拖着后腿呢). 最近做了一个 ...

  6. spring揭密学习笔记(2)-spring ioc容器:IOC的基本概念

    1. IoC的理念就是,让别人为你服务!2. 其实IoC就这么简单!原来是需要什么东西自己去拿,现在是需要什么东西就让别人送过来.一个生动的示例 3.三种依赖注入的方式 IoC模式最权威的总结和解释, ...

  7. uva-565-枚举

    16个披萨配料,选出一种组合满足所有人的需求,当然,如果某个人不喜欢A,结果里不包含A也是满足这个人的.只要答案满足题意既可,答案不唯一,special judge 用位枚举 #include < ...

  8. 27.纯 CSS 创作一个精彩的彩虹 loading 特效

    原文地址:https://segmentfault.com/a/1190000014939781 感想:正方形->圆->旋转一定角度->动画->隐藏下一半 HTML代码: &l ...

  9. python学习笔记_week6_面向对象

    面向对象 介绍(特性(class.object--->封装.继承,多态)).--->世界万物,皆可分类:世界万物,皆可对象 只要是对象,就肯定属于某种品类:只要是对象,就肯定有属性 你是上 ...

  10. 关于 Thread.currentThread()

    currentThread()  到底是什么? 其实currentThread() 只是Thread 的一个静态方法.返回的正是执行当前代码指令的线程引用: /** * Returns a refer ...