ThesearetheIntelliJIDEALiveTemplatesthatI’veusedinmanydemosandscreencastsovertheyears.
IusedIntelliJ’ssharinglivetemplatesfeature,tocreateidea-settings.jar.Youshouldbeabletoimport"MattRaible’sShortcuts"usingthefollowingsteps:
OntheFilemenu,clickImportSettings.
SpecifythepathtotheJARfilewiththeexportedlivetemplateconfiguration.
IntheImportSettingsdialogbox,selecttheLivetemplatescheckboxandclickOK.
AfterrestartingIntelliJIDEA,youwillseetheimportedlivetemplatesontheLiveTemplatespageoftheSettings/PreferencesDialog.
DownloadIntelliJIDEAtoday!It’saspectacularIDEAforJava,Kotlin,TypeScript,JavaScript,S/CSS,andHTML.
Ifyou’drathernotimportallofmytemplates,youcanclonethisprojectandopenitinIntelliJ(withtheAsciidoctorplugininstalled).Youshouldbeabletoeditthisfileandaddtheshortcutsbelowaslivetemplates(Tools>SaveasLiveTemplate).Makesuretosetthefiletypetomatchthelanguage.
SpringBootboot-entity
@javax.persistence.Entityclass$entity${@javax.persistence.Id@javax.persistence.GeneratedValueprivatejava.lang.Longid;privatejava.lang.Stringname;public$entity$(){}public$entity$(Stringname){this.name=name;}publicjava.lang.LonggetId(){returnid;}publicvoidsetId(java.lang.Longid){this.id=id;}publicjava.lang.StringgetName(){returnname;}publicvoidsetName(java.lang.Stringname){this.name=name;}@java.lang.Overridepublicjava.lang.StringtoString(){return"$entity${"+"id="+id+",name='"+name+'\''+'}';}}boot-entity-lombok
@lombok.Data@lombok.AllArgsConstructor@lombok.NoArgsConstructor@javax.persistence.Entityclass$name${public$name$(java.lang.Stringname){this.name=name;}@javax.persistence.Id@javax.persistence.GeneratedValueprivatejava.lang.Longid;privatejava.lang.Stringname;}boot-h2
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId></dependency>boot-sql
insertinto$entity$(name)values('First');insertinto$entity$(name)values('Second');boot-repository
interface$entity$RepositoryextendsJpaRepository<$entity$,java.lang.Long>{}boot-command
@org.springframework.stereotype.Componentclass$entity$CommandLineRunnerimplementsorg.springframework.boot.CommandLineRunner{privatefinal$entity$Repositoryrepository;public$entity$CommandLineRunner($entity$Repositoryrepository){this.repository=repository;}@java.lang.Overridepublicvoidrun(java.lang.String...strings)throwsjava.lang.Exception{repository.findAll().forEach(System.out::println);}}boot-add
//Topbeersfromhttps://www.beeradvocate.com/lists/top/Stream.of("KentuckyBrunchBrandStout","GoodMorning","VeryHazy","KingJulius","Budweiser","CoorsLight","PBR").forEach(name->repository.save(newBeer(name)));boot-controller
@org.springframework.web.bind.annotation.RestControllerclass$entity$Controller{private$entity$Repositoryrepository;public$entity$Controller($entity$Repositoryrepository){this.repository=repository;}@org.springframework.web.bind.annotation.GetMapping("/$uriMapping$")java.util.Collection<$entity$>list(){returnrepository.findAll();}}boot-good
@GetMapping("/good-beers")publicCollection<Beer>goodBeers(){returnrepository.findAll().stream().filter(this::isGreat).collect(Collectors.toList());}privatebooleanisGreat(Beerbeer){return!beer.getName().equals("Budweiser")&&!beer.getName().equals("CoorsLight")&&!beer.getName().equals("PBR");}okta-maven-boot
<dependency><groupId>com.okta.spring</groupId><artifactId>okta-spring-boot-starter</artifactId><version>$version$</version></dependency>spring-oauth2-yaml
spring:security:oauth2:client:registration:okta:client-id:$clientId$client-secret:$clientSecret$provider:okta:authorization-uri:https://$yourOktaDomain$/oauth2/v1/authorizetoken-uri:https://$yourOktaDomain$/oauth2/v1/tokenuser-info-uri:https://$yourOktaDomain$/oauth2/v1/userinfojwk-set-uri:https://$yourOktaDomain$/oauth2/v1/keysokta-oauth2
okta.oauth2.issuer=https://$youtOktaDomain$/oauth2/defaultokta.oauth2.clientId=$clientId$cors-filter
@org.springframework.context.annotation.Beanpublicorg.springframework.boot.web.servlet.FilterRegistrationBeansimpleCorsFilter(){org.springframework.web.cors.UrlBasedCorsConfigurationSourcesource=neworg.springframework.web.cors.UrlBasedCorsConfigurationSource();org.springframework.web.cors.CorsConfigurationconfig=neworg.springframework.web.cors.CorsConfiguration();config.setAllowCredentials(true);config.setAllowedOrigins(java.util.Collections.singletonList("https://localhost:4200"));config.setAllowedMethods(java.util.Collections.singletonList("*"));config.setAllowedHeaders(java.util.Collections.singletonList("*"));source.registerCorsConfiguration("/**",config);org.springframework.boot.web.servlet.FilterRegistrationBeanbean=neworg.springframework.boot.web.servlet.FilterRegistrationBean(neworg.springframework.web.filter.CorsFilter(source));bean.setOrder(org.springframework.core.Ordered.HIGHEST_PRECEDENCE);returnbean;}Angularng-giphy-service
import{Injectable}from'@angular/core';import{HttpClient}from'@angular/common/http';import'rxjs/add/operator/map';@Injectable()//https://tutorials.pluralsight.com/front-end-javascript/getting-started-with-angular-2-by-building-a-giphy-search-applicationexportclassGiphyService{//Publicbetakey:https://github.com/Giphy/GiphyAPI#public-beta-keygiphyApi='//api.giphy.com/v1/gifs/search?api_key=dc6zaTOxFJmzC&limit=1&q=';constructor(publichttp:HttpClient){}get(searchTerm){constapiLink=this.giphyApi+searchTerm;returnthis.http.get(apiLink).map((response:any)=>{if(response.data.length>0){returnresponse.data[0].images.original.url;}else{return'https://media.giphy.com/media/YaOxRsmrv9IeA/giphy.gif';//dancingcatfor404}});}}ng-giphy-foreach
for(const$item$ofthis.$item$s){this.giphyService.get($item$.name).subscribe(url=>$item$.giphyUrl=url);}ng-okta-service
import{Injectable}from'@angular/core';import*asOktaSignInfrom'@okta/okta-signin-widget/dist/js/okta-sign-in.min.js'import{ReplaySubject}from'rxjs/ReplaySubject';import{Observable}from'rxjs/Observable';@Injectable()exportclassOktaAuthService{signIn=newOktaSignIn({baseUrl:'https://$yourOktaDomain$',clientId:'$clientId$',authParams:{issuer:'https://$yourOktaDomain$',responseType:['id_token','token'],scopes:['openid','email','profile']}});publicuser$:Observable<any>;publicuserSource:ReplaySubject<any>;constructor(){this.userSource=newReplaySubject<any>(1);this.user$=this.userSource.asObservable();}isAuthenticated(){//ChecksifthereisacurrentaccessTokenintheTokenManger.return!!this.signIn.tokenManager.get('accessToken');}login(){//Launchesthewidgetandstoresthetokens.this.signIn.renderEl({el:'#okta-signin-container'},response=>{if(response.status==='SUCCESS'){response.forEach(token=>{if(token.idToken){this.signIn.tokenManager.add('idToken',token);}if(token.accessToken){this.signIn.tokenManager.add('accessToken',token);}this.userSource.next(this.idTokenAsUser);this.signIn.hide();});}else{console.error(response);}});}getidTokenAsUser(){consttoken=this.signIn.tokenManager.get('idToken');return{name:token.claims.name,email:token.claims.email,username:token.claims.preferred_username}}asynclogout(){//TerminatesthesessionwithOktaandremovescurrenttokens.this.signIn.tokenManager.clear();awaitthis.signIn.signOut();this.signIn.remove();this.userSource.next(undefined);}}ng-okta-headers
constheaders:Headers=newHeaders();if(this.oktaService.isAuthenticated()){constaccessToken=this.oktaService.signIn.tokenManager.get('accessToken');headers.append('Authorization',accessToken.tokenType+''+accessToken.accessToken);}constoptions=newRequestOptions({headers:headers});ng-okta-oninit
user;constructor(publicoktaService:OktaAuthService,privatechangeDetectorRef:ChangeDetectorRef){}ngOnInit(){//1.forinitialloadandbrowserrefreshif(this.oktaService.isAuthenticated()){this.user=this.oktaService.idTokenAsUser;}else{this.oktaService.login();}//2.registeralistenerforauthenticationandlogoutthis.oktaService.user$.subscribe(user=>{this.user=user;if(!user){this.oktaService.login();}//LetAngularknowthatmodelchanged.//Seehttps://github.com/okta/okta-signin-widget/issues/268formoreinfo.this.changeDetectorRef.detectChanges();});}ng-okta-login
评论