Spring Security使用Hibernate實現自定義UserDetails

大多數時候,我們將需要在Web應用程序中配置自己的安全訪問角色。 這在Spring Security中很容易實現。 在本文中,我們將看到最簡單的方法。

首先,我們將在數據庫中需要以下表格:

CREATE TABLE IF NOT EXISTS `mydb`.`security_role` (`id` INT(11) NOT NULL AUTO_INCREMENT ,`name` VARCHAR(50) NULL DEFAULT NULL ,PRIMARY KEY (`id`) )ENGINE = InnoDBAUTO_INCREMENT = 4DEFAULT CHARACTER SET = latin1;CREATE TABLE IF NOT EXISTS `mydb`.`user` (`id` INT(11) NOT NULL AUTO_INCREMENT ,`first_name` VARCHAR(45) NULL DEFAULT NULL ,`family_name` VARCHAR(45) NULL DEFAULT NULL ,`dob` DATE NULL DEFAULT NULL ,`password` VARCHAR(45) NOT NULL ,`username` VARCHAR(45) NOT NULL ,`confirm_password` VARCHAR(45) NOT NULL ,`active` TINYINT(1) NOT NULL ,PRIMARY KEY (`id`) ,UNIQUE INDEX `username` (`username` ASC) )ENGINE = InnoDBAUTO_INCREMENT = 9DEFAULT CHARACTER SET = latin1;CREATE TABLE IF NOT EXISTS `mydb`.`user_security_role` (`user_id` INT(11) NOT NULL ,`security_role_id` INT(11) NOT NULL ,PRIMARY KEY (`user_id`, `security_role_id`) ,INDEX `security_role_id` (`security_role_id` ASC) ,CONSTRAINT `user_security_role_ibfk_1`FOREIGN KEY (`user_id` )REFERENCES `mydb`.`user` (`id` ),CONSTRAINT `user_security_role_ibfk_2`FOREIGN KEY (`security_role_id` )REFERENCES `mydb`.`security_role` (`id` ))ENGINE = InnoDBDEFAULT CHARACTER SET = latin1;

顯然,表用戶將擁有用戶,表security_role將擁有安全角色,而user_security_roles將擁有關聯。 為了使實現盡可能簡單,security_role表中的條目應始終以“ ROLE_”開頭,否則我們將需要封裝(本文將不涉及)。

因此,我們執行以下語句:

insert into security_role(name) values ('ROLE_admin');insert into security_role(name) values ('ROLE_Kennel_Owner');insert into security_role(name) values ('ROLE_User');insert into user (first_name,family_name,password,username,confirm_password,active)values ('ioannis','ntantis','123456','giannisapi','123456',1);insert into user_security_role (user_id,security_role_id) values (1,1);

因此,執行這些命令后,我們將得到以下內容:

三種不同的安全角色

一位用戶名為“ giannisapi”的用戶

我們已將角色“ ROLE_admin”賦予用戶“ giannisapi”

現在,一切都已在數據庫端完成,我們將移至Java端,看看需要做什么。

首先,我們將創建必要的DTO(有多種工具可以為您自動從數據庫生成DTO):

package org.intan.pedigree.form;import java.io.Serializable;import java.util.Collection;import java.util.Date;import java.util.Set;import javax.persistence.Basic;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.JoinTable;import javax.persistence.ManyToMany;import javax.persistence.NamedQueries;import javax.persistence.NamedQuery;import javax.persistence.Table;import javax.persistence.Temporal;import javax.persistence.TemporalType;/**** @author intan*/@Entity@Table(name = 'user', catalog = 'mydb', schema = '')@NamedQueries({@NamedQuery(name = 'UserEntity.findAll', query = 'SELECT u FROM UserEntity u'),@NamedQuery(name = 'UserEntity.findById', query = 'SELECT u FROM UserEntity u WHERE u.id = :id'),@NamedQuery(name = 'UserEntity.findByFirstName', query = 'SELECT u FROM UserEntity u WHERE u.firstName = :firstName'),@NamedQuery(name = 'UserEntity.findByFamilyName', query = 'SELECT u FROM UserEntity u WHERE u.familyName = :familyName'),@NamedQuery(name = 'UserEntity.findByDob', query = 'SELECT u FROM UserEntity u WHERE u.dob = :dob'),@NamedQuery(name = 'UserEntity.findByPassword', query = 'SELECT u FROM UserEntity u WHERE u.password = :password'),@NamedQuery(name = 'UserEntity.findByUsername', query = 'SELECT u FROM UserEntity u WHERE u.username = :username'),@NamedQuery(name = 'UserEntity.findByConfirmPassword', query = 'SELECT u FROM UserEntity u WHERE u.confirmPassword = :confirmPassword'),@NamedQuery(name = 'UserEntity.findByActive', query = 'SELECT u FROM UserEntity u WHERE u.active = :active')})public class UserEntity implements Serializable {private static final long serialVersionUID = 1L;@Id@GeneratedValue(strategy = GenerationType.IDENTITY)@Basic(optional = false)@Column(name = 'id')private Integer id;@Column(name = 'first_name')private String firstName;@Column(name = 'family_name')private String familyName;@Column(name = 'dob')@Temporal(TemporalType.DATE)private Date dob;@Basic(optional = false)@Column(name = 'password')private String password;@Basic(optional = false)@Column(name = 'username')private String username;@Basic(optional = false)@Column(name = 'confirm_password')private String confirmPassword;@Basic(optional = false)@Column(name = 'active')private boolean active;@JoinTable(name = 'user_security_role', joinColumns = {@JoinColumn(name = 'user_id', referencedColumnName = 'id')}, inverseJoinColumns = {@JoinColumn(name = 'security_role_id', referencedColumnName = 'id')})@ManyToManyprivate Set securityRoleCollection;public UserEntity() {}public UserEntity(Integer id) {this.id = id;}public UserEntity(Integer id, String password, String username, String confirmPassword, boolean active) {this.id = id;this.password = password;this.username = username;this.confirmPassword = confirmPassword;this.active = active;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getFirstName() {return firstName;}public void setFirstName(String firstName) {this.firstName = firstName;}public String getFamilyName() {return familyName;}public void setFamilyName(String familyName) {this.familyName = familyName;}public Date getDob() {return dob;}public void setDob(Date dob) {this.dob = dob;}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;}public String getConfirmPassword() {return confirmPassword;}public void setConfirmPassword(String confirmPassword) {this.confirmPassword = confirmPassword;}public boolean getActive() {return active;}public void setActive(boolean active) {this.active = active;}public Set getSecurityRoleCollection() {return securityRoleCollection;}public void setSecurityRoleCollection(Set securityRoleCollection) {this.securityRoleCollection = securityRoleCollection;}@Overridepublic int hashCode() {int hash = 0;hash += (id != null ? id.hashCode() : 0);return hash;}@Overridepublic boolean equals(Object object) {// TODO: Warning - this method won't work in the case the id fields are not setif (!(object instanceof UserEntity)) {return false;}UserEntity other = (UserEntity) object;if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {return false;}return true;}@Overridepublic String toString() {return 'org.intan.pedigree.form.User[id=' + id + ']';}}
package org.intan.pedigree.form;import java.io.Serializable;import java.util.Collection;import javax.persistence.Basic;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.ManyToMany;import javax.persistence.NamedQueries;import javax.persistence.NamedQuery;import javax.persistence.Table;/**** @author intan*/@Entity@Table(name = 'security_role', catalog = 'mydb', schema = '')@NamedQueries({@NamedQuery(name = 'SecurityRoleEntity.findAll', query = 'SELECT s FROM SecurityRoleEntity s'),@NamedQuery(name = 'SecurityRoleEntity.findById', query = 'SELECT s FROM SecurityRoleEntity s WHERE s.id = :id'),@NamedQuery(name = 'SecurityRoleEntity.findByName', query = 'SELECT s FROM SecurityRoleEntity s WHERE s.name = :name')})public class SecurityRoleEntity implements Serializable {private static final long serialVersionUID = 1L;@Id@GeneratedValue(strategy = GenerationType.IDENTITY)@Basic(optional = false)@Column(name = 'id')private Integer id;@Column(name = 'name')private String name;@ManyToMany(mappedBy = 'securityRoleCollection')private Collection userCollection;public SecurityRoleEntity() {}public SecurityRoleEntity(Integer id) {this.id = id;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Collection getUserCollection() {return userCollection;}public void setUserCollection(Collection userCollection) {this.userCollection = userCollection;}@Overridepublic int hashCode() {int hash = 0;hash += (id != null ? id.hashCode() : 0);return hash;}@Overridepublic boolean equals(Object object) {// TODO: Warning - this method won't work in the case the id fields are not setif (!(object instanceof SecurityRoleEntity)) {return false;}SecurityRoleEntity other = (SecurityRoleEntity) object;if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {return false;}return true;}@Overridepublic String toString() {return 'org.intan.pedigree.form.SecurityRole[id=' + id + ']';}}

現在我們已經有了DTO,讓我們創建必要的DAO類:

package org.intan.pedigree.dao;import java.util.List;import java.util.Set;import org.hibernate.SessionFactory;import org.intan.pedigree.form.SecurityRoleEntity;import org.intan.pedigree.form.UserEntity;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;@Repositorypublic class UserEntityDAOImpl implements UserEntityDAO{@Autowiredprivate SessionFactory sessionFactory;public void addUser(UserEntity user) {try {sessionFactory.getCurrentSession().save(user);} catch (Exception e) {System.out.println(e);}}public UserEntity findByName(String username) {UserEntity user = (UserEntity) sessionFactory.getCurrentSession().createQuery('select u from UserEntity u where u.username = '' + username + ''').uniqueResult();return user;}public UserEntity getUserByID(Integer id) {UserEntity user = (UserEntity) sessionFactory.getCurrentSession().createQuery('select u from UserEntity u where id = '' + id + ''').uniqueResult();return user;}public String activateUser(Integer id) {String hql = 'update UserEntityset active = :active where id = :id';org.hibernate.Query query = sessionFactory.getCurrentSession().createQuery(hql);query.setString('active','Y');query.setInteger('id',id);int rowCount = query.executeUpdate();System.out.println('Rows affected: ' + rowCount);return '';}public String disableUser(Integer id) {String hql = 'update UserEntity set active = :active where id = :id';org.hibernate.Query query = sessionFactory.getCurrentSession().createQuery(hql);query.setInteger('active',0);query.setInteger('id',id);int rowCount = query.executeUpdate();System.out.println('Rows affected: ' + rowCount);return '';}public void updateUser(UserEntity user) {try {sessionFactory.getCurrentSession().update(user);} catch (Exception e) {System.out.println(e);}}public List listUser() {return sessionFactory.getCurrentSession().createQuery('from UserEntity').list();}public void removeUser(Integer id) {UserEntity user = (UserEntity) sessionFactory.getCurrentSession().load(UserEntity.class, id);if (null != user) {sessionFactory.getCurrentSession().delete(user);}}public Set getSecurityRolesForUsername(String username) {UserEntity user = (UserEntity) sessionFactory.getCurrentSession().createQuery('select u from UserEntity u where u.username = '' + username + ''').uniqueResult();if (user!= null) {Set roles = (Set) user.getSecurityRoleCollection();if (roles != null && roles.size() > 0) {return roles;}}return null;}}
package org.intan.pedigree.dao;import java.util.List;import org.hibernate.Criteria;import org.hibernate.SessionFactory;import org.hibernate.criterion.Restrictions;import org.intan.pedigree.form.Country;import org.intan.pedigree.form.Kennel;import org.intan.pedigree.form.SecurityRoleEntity;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;@Repositorypublic class SecurityRoleEntityDAOImpl implements SecurityRoleEntityDAO{@Autowiredprivate SessionFactory sessionFactory;public void addSecurityRoleEntity(SecurityRoleEntity securityRoleEntity) {try {sessionFactory.getCurrentSession().save(securityRoleEntity);} catch (Exception e) {System.out.println(e);}}public List listSecurityRoleEntity() {Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SecurityRoleEntity.class);criteria.add(Restrictions.ne('name','ROLE_ADMIN' ));return criteria.list();}public SecurityRoleEntity getSecurityRoleEntityById(Integer id) {Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SecurityRoleEntity.class);criteria.add(Restrictions.eq('id',id));return (SecurityRoleEntity) criteria.uniqueResult();}public void removeSecurityRoleEntity(Integer id) {SecurityRoleEntity securityRoleEntity = (SecurityRoleEntity) sessionFactory.getCurrentSession().load(SecurityRoleEntity.class, id);if (null != securityRoleEntity) {sessionFactory.getCurrentSession().delete(securityRoleEntity);}}}

現在,我們將為上述DAO創建服務層。

package org.intan.pedigree.service;import java.util.List;import org.intan.pedigree.dao.SecurityRoleEntityDAO;import org.intan.pedigree.form.SecurityRoleEntity;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;@Servicepublic class SecurityRoleEntityServiceImpl implements SecurityRoleEntityService{@Autowiredprivate SecurityRoleEntityDAO securityRoleEntityDAO;@Transactionalpublic void addSecurityRoleEntity(SecurityRoleEntity securityRoleEntity) {securityRoleEntityDAO.addSecurityRoleEntity(securityRoleEntity);}@Transactionalpublic List listSecurityRoleEntity() {return securityRoleEntityDAO.listSecurityRoleEntity();}@Transactionalpublic void removeSecurityRoleEntity(Integer id) {securityRoleEntityDAO.removeSecurityRoleEntity(id);}@Transactionalpublic SecurityRoleEntity getSecurityRoleEntityById(Integer id) {return securityRoleEntityDAO.getSecurityRoleEntityById( id);}}

在下面的UserDetails的服務層中,請注意它是從org.springframework.security.core.userdetails.UserDetailsS??ervice實現UserDetailsS??ervice的。

package org.intan.pedigree.service;import org.intan.pedigree.dao.UserEntityDAO;import org.intan.pedigree.dao.UserEntityDAO;import org.intan.pedigree.form.UserEntity;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.dao.DataAccessException;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import org.springframework.security.core.userdetails.User;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UserDetailsService;import org.springframework.security.core.userdetails.UsernameNotFoundException;@Service('userDetailsService')public class UserDetailsServiceImpl implements UserDetailsService {@Autowiredprivate UserEntityDAO dao;@Autowiredprivate Assembler assembler;@Transactional(readOnly = true)public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException {UserDetails userDetails = null;UserEntity userEntity = dao.findByName(username);if (userEntity == null)throw new UsernameNotFoundException('user not found');return assembler.buildUserFromUserEntity(userEntity);}}

您還在上面看到,loadUserByUsername方法返回assembler.buildUserFromUserEntity的結果。 簡而言之,匯編程序的這種方法是從給定的UserEntity DTO構造一個org.springframework.security.core.userdetails.User對象。 下面給出了Assembler類的代碼:

package org.intan.pedigree.service;import java.util.ArrayList;import java.util.Collection;import org.intan.pedigree.form.SecurityRoleEntity;import org.intan.pedigree.form.UserEntity;import org.springframework.security.core.GrantedAuthority;import org.springframework.security.core.authority.GrantedAuthorityImpl;import org.springframework.security.core.userdetails.User;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;@Service('assembler')public class Assembler {@Transactional(readOnly = true)User buildUserFromUserEntity(UserEntity userEntity) {String username = userEntity.getUsername();String password = userEntity.getPassword();boolean enabled = userEntity.getActive();boolean accountNonExpired = userEntity.getActive();boolean credentialsNonExpired = userEntity.getActive();boolean accountNonLocked = userEntity.getActive();Collection authorities = new ArrayList();for (SecurityRoleEntity role : userEntity.getSecurityRoleCollection()) {authorities.add(new GrantedAuthorityImpl(role.getName()));}User user = new User(username, password, enabled,accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);return user;}}

現在剩下要做的唯一事情就是定義applicationContext-Security.xml中必需的內容。 為此,創建一個具有以下內容的名為“ applicationContext-Security.xml”的新xml文件:

<?xml version='1.0' encoding='UTF-8'?>
<beans:beans xmlns='http://www.springframework.org/schema/security'xmlns:beans='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns:context='http://www.springframework.org/schema/context'xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd'><beans:bean id='userDetailsService' class='org.intan.pedigree.service.UserDetailsServiceImpl'></beans:bean><context:component-scan base-package='org.intan.pedigree' /><http auto-config='true'><intercept-url pattern='/admin/**' access='ROLE_ADMIN' /><intercept-url pattern='/user/**' access='ROLE_REGISTERED_USER' /><intercept-url pattern='/kennel/**' access='ROLE_KENNEL_OWNER' /><!-- <security:intercept-url pattern='/login.jsp' access='IS_AUTHENTICATED_ANONYMOUSLY' />  --></http><beans:bean id='daoAuthenticationProvider'class='org.springframework.security.authentication.dao.DaoAuthenticationProvider'><beans:property name='userDetailsService' ref='userDetailsService' /></beans:bean><beans:bean id='authenticationManager'class='org.springframework.security.authentication.ProviderManager'><beans:property name='providers'><beans:list><beans:ref local='daoAuthenticationProvider' /></beans:list></beans:property></beans:bean><authentication-manager><authentication-provider user-service-ref='userDetailsService'><password-encoder hash='plaintext' /></authentication-provider></authentication-manager></beans:beans>

在您的web.xml中放入以下代碼,以加載applicationContext-security.xml文件。

<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext-hibernate.xml/WEB-INF/applicationContext-security.xml</param-value></context-param>

最后,請原諒任何輸入錯誤等,因為此代碼只是從我完成的個人工作中復制和粘貼的內容,如果某些操作不起作用,請提出問題,我們將非常樂意為您提供幫助。

參考: Spring 3,Spring Security在Giannisapi博客上與我們的JCG合作伙伴 Ioannis Dadis 一起使用Hibernate實現自定義用戶 詳細信息 。


翻譯自: https://www.javacodegeeks.com/2012/08/spring-security-implementing-custom.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/371958.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/371958.shtml
英文地址,請注明出處:http://en.pswp.cn/news/371958.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python之路-面向對象

編程范式 編程是 程序 員 用特定的語法數據結構算法組成的代碼來告訴計算機如何執行任務的過程 &#xff0c; 一個程序是程序員為了得到一個任務結果而編寫的一組指令的集合&#xff0c;正所謂條條大路通羅馬&#xff0c;實現一個任務的方式有很多種不同的方式&#xff0c; 對這…

西安郵電大學計算機科學與技術有專碩嗎,2020年西安郵電大學計算機學院考研擬錄取名單及排名!...

20考研復試調劑群&#xff1a;4197552812020年西安郵電大學計算機學院碩士研究生招生復試成績及綜合排名各位考生&#xff1a;現將我院2020年碩士研究生招生復試成績及綜合排名公布(最終錄取名單及新生學籍注冊均以“全國碩士研究生招生信息公開平臺”備案信息為準)&#xff0c…

用Java排序的五種有用方法

Java排序快速概述&#xff1a; 正常的列表&#xff1a; private static List VEGETABLES Arrays.asList("apple", "cocumbers", "blackberry");Collections.sort(VEGETABLES);output: apple, blackberry, cocumbers反向排序&#xff1a; pri…

[python]-數據科學庫Numpy學習

一、Numpy簡介&#xff1a; Python中用列表(list)保存一組值&#xff0c;可以用來當作數組使用&#xff0c;不過由于列表的元素可以是任何對象&#xff0c;因此列表中所保存的是對象的指針。這樣為了保存一個簡單的[1,2,3]&#xff0c;需要有3個指針和三個整數對象。對于數值運…

檢測一個點, 是否在一個半圓之內的方法

demo: http://jsbin.com/lihiwigaso 需求: 一個圓分成分部分, 鼠標滑上不同的區域顯示不同的顏色 思路: 先判斷這個點是否在圓之內, 再判斷是否在所在的三角形之內就可以了 所需要的全部源碼: <!DOCTYPE html> <html> <head><meta charset"utf-8&quo…

計算機網絡設備接地規范,網絡機房防雷接地的四種方式及靜電要求

編輯----河南新時代防雷由于計算機網絡系統的核心設備都放置在網絡機房內&#xff0c;因而網絡機房防雷接地有了較高的環境要求&#xff0c;良好的接地系統是保證機房計算機及網絡設備安全運行&#xff0c;以及工作人員人身安全的重要措施。直流地的接法通常采用網格地&#xf…

抓住尾部的StackOverFlowError

使用Java程序時可能要處理的一種更煩人的情況是StackOverFlowError&#xff0c;如果您有一個很好的可生產的測試用例&#xff0c;那么關于使用堆棧大小或設置條件斷點/某種痕跡 。 但是&#xff0c;如果您有一個測試案例可能一次失敗100次&#xff0c;或者像我的案例一樣在AWTM…

Gunicorn配置部分的翻譯

寫在前面&#xff0c;雖然翻譯得很爛&#xff0c;但也是我的勞動成果&#xff0c;轉載請注明出處&#xff0c;謝謝。 Gunicorn版本號19.7.1 Gunicorn配置 概述 三種配置方式 優先級如下&#xff0c;越后的優先級越大 1.框架的設置&#xff08;現在只有paster在用這個&#xff0…

臺式計算機風扇聲音大怎么處理,如何解決電腦電源風扇聲音大的問題?

現在的臺式機一般用3到5年后&#xff0c;一些問題自然也就慢慢表現出來了。很多網友在使用電腦過程中都有電腦風扇聲音大怎么辦的問題&#xff0c;電腦風扇聲音大就會讓人覺得使用電腦很不舒服&#xff0c;怎么辦好呢&#xff1f;出現重要的問題要如何解決好呢&#xff1f;現在…

jsp分頁功能

http://blog.csdn.net/xiazdong/article/details/6857515轉載于:https://www.cnblogs.com/Baronboy/p/6112403.html

Spring Security第1部分–具有數據庫的簡單登錄應用程序

什么是Spring Security&#xff1f; Spring Security是一個提供安全解決方案的框架&#xff0c;可在Web請求級別和方法級別上處理身份驗證和授權。 Spring安全性通過兩種方式處理安全性。 一種是安全的Web請求&#xff0c;另一種是在URL級別限制訪問。 Spring Security使用Serv…

計算機應用 winxp,2017年職稱計算機考試模塊WindowsXP試題

2017年職稱計算機考試模塊WindowsXP試題全國專業技術人員計算機應用能力考試是專業技術人員資格考試的一種。接下來應屆畢業生小編為大家搜索整理了2017年職稱計算機考試模塊WindowsXP試題&#xff0c;希望大家有所幫助。1. Windows XP中刪除某個文件的快捷方式【 A 】。A. 對原…

Python基礎(8)_迭代器、生成器、列表解析

一、迭代器 1、什么是迭代 1 重復   2 下次重復一定是基于上一次的結果而來 1 l[1,2,3,4] 2 count0 3 while count < len(l): 4 print(l[count]) 5 count1 迭代舉例2、可迭代對象 可進行.__iter__()操作的為可迭代對象 #print(isinstance(str1,Iterable)),判斷str…

Angularjs2-EXCEPTION: Response with status: 200 Ok for URL:

利用jsonp跨域請求數居&#xff0c;報錯 core.umd.js:3070 EXCEPTION: Response with status: 200 Ok for URL: 參考&#xff1a;stackoverflow 未解決。。。腦仁疼。。。有小伙伴也碰到過這個問題么&#xff1f; 16/11/30 問題解決 1.服務器端API允許跨域訪問(返回的數據添加允…

圖片無法刪除要計算機管理員,存在桌面的圖片刪不掉,怎么處理?提示是需要管理員權限。...

將下面代碼復制到記事本里&#xff0c;重命名為1.bat&#xff0c;然后打開&#xff0c;這時你右鍵圖片會出現管理員取得所有權&#xff0c;然后取得所有權后再刪除試試Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\*\shell\runas]管理員取得所有權NoWorkingDirecto…

Java對象序列化的本機C / C ++類似性能

您是否曾經希望過像使用C 這樣的本地語言將Java對象轉換成字節流一樣快的速度&#xff1f; 如果您使用標準的Java序列化&#xff0c;您可能會對性能感到失望。 Java序列化的目的是與盡可能快而緊湊地序列化對象的目的截然不同。 為什么我們需要快速緊湊的序列化&#xff1f; 我…

WebStrom Sass 編譯配置 windows

第一步&#xff1a; 先安裝Ruby下載 一路next 安裝完成后打開開始菜單 打開后輸入 gem install sass sass -v 出現版本號說明成功 第二部配置webstorm 在webstorm中settings中搜索file watchers工具&#xff0c;在此工具中添加一個scss的watcher 確定&#xff0c;打開一個scss…

非本地跳轉之setjmp與longjmp

非本地跳轉(unlocal jump)是與本地跳轉相對應的一個概念。 本地跳轉主要指的是類似于goto語句的一系列應用&#xff0c;當設置了標志之后&#xff0c;可以跳到所在函數內部的標號上。然而&#xff0c;本地跳轉不能將控制權轉移到所在程序的任意地點&#xff0c;不能跨越函數&am…

清華計算機自主招生試題,2017年清華大學自主招生筆試題

2017年清華大學自主招生筆試題2017高考結束后&#xff0c;全國各大高校自主招生面試開始了&#xff0c;以下是百分網小編搜索整理的關于2017年清華大學自主招生筆試題&#xff0c;供各位參考&#xff0c;希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試網!…

擴展劑:模式還是反模式?

擴展器模式在最近幾年變得很流行&#xff0c;甚至已經在OSGi標準&#xff08;例如&#xff0c;藍圖服務和Web應用程序規范&#xff09;中使用。 在處女座&#xff0c;我們從一開始就與擴展程序一起工作&#xff0c;但是盡管它們具有優勢&#xff0c;但它們仍有一些明顯的缺點。…