├── src ├── assets │ ├── .gitkeep │ └── img │ │ ├── dao.jpg │ │ ├── xml.jpg │ │ ├── entity.jpg │ │ ├── code_arch.jpg │ │ ├── from_disk.jpg │ │ ├── generate.jpg │ │ ├── refresh.jpg │ │ ├── settings.jpg │ │ ├── activation.jpg │ │ ├── base_entity.jpg │ │ ├── after_generation.jpg │ │ ├── after_installation.jpg │ │ ├── before_generation.jpg │ │ └── tool_window_position.jpg ├── favicon.ico ├── app │ ├── config │ │ ├── config.component.css │ │ ├── config.component.ts │ │ ├── config.component.html │ │ └── config.component.spec.ts │ ├── install │ │ ├── install.component.css │ │ ├── install.component.ts │ │ ├── install.component.html │ │ └── install.component.spec.ts │ ├── code-intro │ │ ├── code-intro.component.css │ │ ├── code-intro.component.ts │ │ ├── code-intro.component.spec.ts │ │ └── code-intro.component.html │ ├── app.component.ts │ ├── usage │ │ ├── usage.component.css │ │ ├── usage.component.html │ │ ├── usage.component.spec.ts │ │ └── usage.component.ts │ ├── nav │ │ ├── nav.component.ts │ │ ├── nav.component.css │ │ ├── nav.component.html │ │ └── nav.component.spec.ts │ ├── material.module.spec.ts │ ├── method-usage.ts │ ├── app.component.html │ ├── app.component.css │ ├── app.component.spec.ts │ ├── material.module.ts │ └── app.module.ts ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── tsconfig.app.json ├── styles.css ├── tsconfig.spec.json ├── tslint.json ├── browserslist ├── main.ts ├── index.html ├── test.ts ├── karma.conf.js └── polyfills.ts ├── .gitignore ├── e2e ├── src │ ├── app.po.ts │ └── app.e2e-spec.ts ├── tsconfig.e2e.json └── protractor.conf.js ├── tsconfig.json ├── package.json ├── README.md ├── tslint.json └── angular.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/app/config/config.component.css: -------------------------------------------------------------------------------- 1 | img { 2 | max-width: 60%; 3 | max-height: 450px; 4 | } 5 | -------------------------------------------------------------------------------- /src/assets/img/dao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/dao.jpg -------------------------------------------------------------------------------- /src/assets/img/xml.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/xml.jpg -------------------------------------------------------------------------------- /src/app/install/install.component.css: -------------------------------------------------------------------------------- 1 | img { 2 | max-width: 60%; 3 | max-height: 450px; 4 | } 5 | -------------------------------------------------------------------------------- /src/assets/img/entity.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/entity.jpg -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/app/code-intro/code-intro.component.css: -------------------------------------------------------------------------------- 1 | img { 2 | max-width: 60%; 3 | max-height: 450px; 4 | } 5 | -------------------------------------------------------------------------------- /src/assets/img/code_arch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/code_arch.jpg -------------------------------------------------------------------------------- /src/assets/img/from_disk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/from_disk.jpg -------------------------------------------------------------------------------- /src/assets/img/generate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/generate.jpg -------------------------------------------------------------------------------- /src/assets/img/refresh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/refresh.jpg -------------------------------------------------------------------------------- /src/assets/img/settings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/settings.jpg -------------------------------------------------------------------------------- /src/assets/img/activation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/activation.jpg -------------------------------------------------------------------------------- /src/assets/img/base_entity.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/base_entity.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /node_modules/ 3 | *.classpath 4 | *.project 5 | *.idea/ 6 | *.settings 7 | /dist/ 8 | 9 | -------------------------------------------------------------------------------- /src/assets/img/after_generation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/after_generation.jpg -------------------------------------------------------------------------------- /src/assets/img/after_installation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/after_installation.jpg -------------------------------------------------------------------------------- /src/assets/img/before_generation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/before_generation.jpg -------------------------------------------------------------------------------- /src/assets/img/tool_window_position.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiye/yobatis/HEAD/src/assets/img/tool_window_position.jpg -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~@angular/material/prebuilt-themes/indigo-pink.css"; 3 | 4 | html, body { height: 100%; } 5 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 6 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'yobatis-tour'; 10 | } 11 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /src/app/usage/usage.component.css: -------------------------------------------------------------------------------- 1 | mat-card { 2 | margin-top: 10px; 3 | margin-bottom: 20px; 4 | 5 | } 6 | 7 | mat-card-content pre { 8 | background: rgba(0,0,0,.01); 9 | border: .5px solid rgba(0,0,0,.03); 10 | border-radius: 5px; 11 | padding: 5px 20px; 12 | } 13 | 14 | .method { 15 | font-size: 16px; 16 | } 17 | -------------------------------------------------------------------------------- /src/app/nav/nav.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-nav', 5 | templateUrl: './nav.component.html', 6 | styleUrls: ['./nav.component.css'] 7 | }) 8 | export class NavComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/app/config/config.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-config', 5 | templateUrl: './config.component.html', 6 | styleUrls: ['./config.component.css'] 7 | }) 8 | export class ConfigComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/install/install.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-install', 5 | templateUrl: './install.component.html', 6 | styleUrls: ['./install.component.css'] 7 | }) 8 | export class InstallComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/material.module.spec.ts: -------------------------------------------------------------------------------- 1 | import { MaterialModule } from './material.module'; 2 | 3 | describe('MaterialModule', () => { 4 | let materialModule: MaterialModule; 5 | 6 | beforeEach(() => { 7 | materialModule = new MaterialModule(); 8 | }); 9 | 10 | it('should create an instance', () => { 11 | expect(materialModule).toBeTruthy(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to yobatis-tour!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/app/code-intro/code-intro.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-code-intro', 5 | templateUrl: './code-intro.component.html', 6 | styleUrls: ['./code-intro.component.css'] 7 | }) 8 | export class CodeIntroComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/app/method-usage.ts: -------------------------------------------------------------------------------- 1 | 2 | export class MethodUsage { 3 | name: string; 4 | brief: string; 5 | doc: string; 6 | returnValue: string; 7 | example: string; 8 | 9 | constructor(name: string, brief: string, doc: string, returnValue: string, example: string) { 10 | this.name = name; 11 | this.brief = brief; 12 | this.doc = doc; 13 | this.returnValue = returnValue; 14 | this.example = example; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import 'hammerjs'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | 5 | import { AppModule } from './app/app.module'; 6 | import { environment } from './environments/environment'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | 15 | -------------------------------------------------------------------------------- /src/app/nav/nav.component.css: -------------------------------------------------------------------------------- 1 | mat-sidenav { 2 | width: 300px; 3 | } 4 | 5 | mat-list-item { 6 | padding: 0; 7 | } 8 | mat-list-item .mat-list-item-content { 9 | padding: 0; 10 | } 11 | a.active-list-item { 12 | background-color: #3f51b5; 13 | color: white; 14 | } 15 | a.active-list-item:active, a.active-list-item:focus { 16 | background-color: #3f51b5; 17 | color: white; 18 | } 19 | mat-list-item a { 20 | width: 100%; 21 | height: 100%; 22 | line-height: 48px; 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "node_modules/@types" 15 | ], 16 | "lib": [ 17 | "es2017", 18 | "dom" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Yobatis 使用手册 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | YobatisTour 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/app/nav/nav.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 安装Yobatis 4 | 5 | 6 | 7 | 配置Yobatis 8 | 9 | 10 | 11 | 代码速览 12 | 13 | 14 | 15 | 代码使用 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/app/config/config.component.html: -------------------------------------------------------------------------------- 1 |

2 | 配置 3 |

4 | 5 |
6 |

使用Yobatis之前需要配置mysql数据库,单击Yobatis图标(第1步)弹出窗口,单击Config显示配置(第2步),单击Refresh显示当前库中的表(第三步):

7 | 8 |

填入代码生成位置以及生成, java文件的package名字, xml mapper的位置,单击Generate(第4步)即可生成对应的DAO/Entity/Xml Mapper代码:

9 | 10 |

生成前后对比(完整示例请git clone https://github.com/linbaiye/yobatis-sample.git)

11 | 12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/app/install/install.component.html: -------------------------------------------------------------------------------- 1 |

2 | 安装 3 |

4 | 5 |
6 |

7 | Yobatis目前只支持从本地安装,请到https://github.com/linbaiye/yobatis下载最新release。下载后找到IDEA的Preference/Settings目录,选择Plugins,通过Install Plugin From Disk安装,选择zip包即可,不需要解压: 8 |

9 | 10 | 11 |

12 | 安装完成并重启后会在右侧显示Yobatis ToolWindow的按钮。如下图: 13 |

14 | 15 |

16 | 若没有该ToolWindow的按钮,请检查View -> Tool Windows,如下图: 17 |

18 | 19 |
20 | -------------------------------------------------------------------------------- /src/app/usage/usage.component.html: -------------------------------------------------------------------------------- 1 |

使用生成文件

2 | 3 |

下面以表create table employee(id bigint primary key auto_increment, name char(20), phone char(12)) 作为示例,介绍各个CURD接口的使用方法。

4 | 5 | 6 | {{usage.name}} 7 | {{usage.brief}} 8 | 9 | 10 |

11 | {{usage.doc}} 12 |

13 |

14 | {{usage.returnValue}} 15 |

16 |
17 |       
18 |         {{usage.example}}
19 |       
20 |     
21 |
22 |
23 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/app/nav/nav.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NavComponent } from './nav.component'; 4 | 5 | describe('NavComponent', () => { 6 | let component: NavComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ NavComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NavComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/app/usage/usage.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UsageComponent } from './usage.component'; 4 | 5 | describe('UsageComponent', () => { 6 | let component: UsageComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UsageComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UsageComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/config/config.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ConfigComponent } from './config.component'; 4 | 5 | describe('ConfigComponent', () => { 6 | let component: ConfigComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ConfigComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ConfigComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/install/install.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { InstallComponent } from './install.component'; 4 | 5 | describe('InstallComponent', () => { 6 | let component: InstallComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ InstallComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(InstallComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/code-intro/code-intro.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CodeIntroComponent } from './code-intro.component'; 4 | 5 | describe('CodeIntroComponent', () => { 6 | let component: CodeIntroComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CodeIntroComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CodeIntroComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | 2 | mat-sidenav { 3 | box-shadow: 1px 1px 1px 1px rgba(63, 81, 131, .2); 4 | } 5 | 6 | .query-bar-box { 7 | height: 2px; 8 | padding: 0; 9 | } 10 | 11 | .query-bar-box mat-progress-bar { 12 | width: 100%; 13 | height: 2px; 14 | } 15 | 16 | .hidden { 17 | display: none; 18 | } 19 | 20 | mat-sidenav-container { 21 | margin-top: 50px; 22 | background-color: white; 23 | 24 | /*height: calc(100vh - 50px);*/ 25 | } 26 | 27 | #header mat-toolbar-row:first-child { 28 | height: 50px; 29 | } 30 | #header { 31 | top: 0; 32 | height: 50px; 33 | position: fixed; 34 | z-index: 100; 35 | min-height: 50px; 36 | } 37 | mat-sidenav { 38 | top: 50px; 39 | position: fixed; 40 | } 41 | mat-sidenav-content { 42 | padding-left: 5%; 43 | padding-right: 5%; 44 | padding-bottom: 10px; 45 | } 46 | #header span { 47 | font-size: 14px; 48 | flex: 1 1 auto; 49 | } 50 | #header span:last-child { 51 | text-align: right; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | describe('AppComponent', () => { 4 | beforeEach(async(() => { 5 | TestBed.configureTestingModule({ 6 | declarations: [ 7 | AppComponent 8 | ], 9 | }).compileComponents(); 10 | })); 11 | it('should create the app', async(() => { 12 | const fixture = TestBed.createComponent(AppComponent); 13 | const app = fixture.debugElement.componentInstance; 14 | expect(app).toBeTruthy(); 15 | })); 16 | it(`should have as title 'yobatis-tour'`, async(() => { 17 | const fixture = TestBed.createComponent(AppComponent); 18 | const app = fixture.debugElement.componentInstance; 19 | expect(app.title).toEqual('yobatis-tour'); 20 | })); 21 | it('should render title in a h1 tag', async(() => { 22 | const fixture = TestBed.createComponent(AppComponent); 23 | fixture.detectChanges(); 24 | const compiled = fixture.debugElement.nativeElement; 25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to yobatis-tour!'); 26 | })); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/code-intro/code-intro.component.html: -------------------------------------------------------------------------------- 1 |

2 | 代码速览 3 |

4 | 5 |
6 |

在Yobatis Tool Window中单击Generate以后,Yobatis会为表employee生成如下文件

7 | 8 |
9 |
10 |

EmployeeDao.java

11 | 12 |

常用的CURD signature,生成后Yobatis不会覆写,可在该文件中添加自定义方法。具体使用请访问"代码使用":

13 | 14 |
15 |
16 |

BaseEmployee.java

17 | 18 |

根据表生成的实体类,包含表中所有字段,表结构发生变更后,重新Generate即可。Yobatis每次Generate会覆盖该文件,请勿修改。

19 | 20 |
21 |
22 |

Employee.java

23 | 24 |

配合BaseYobatis使用,可在该类中添加自定义field, method,生成后Yobatis不会覆写该文件。

25 | 26 |
27 |
28 |

EmployeeMapper.xml

29 | 30 |

Mybatis mapper文件,可在该文件中添加tag,Yobatis每次都会覆写自动生成的tag,保留自定义tag。

31 | 32 |
33 |

34 | 请git clone https://github.com/linbaiye/yobatis-sample.git 查看完整示例项目。 35 |

36 | -------------------------------------------------------------------------------- /src/app/material.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { 3 | MatButtonModule, 4 | MatCardModule, MatCheckboxModule, MatExpansionModule, MatFormFieldModule, MatGridListModule, 5 | MatIconModule, MatInputModule, 6 | MatListModule, 7 | MatMenuModule, MatProgressBarModule, MatProgressSpinnerModule, MatSidenavModule, 8 | MatToolbarModule 9 | } from '@angular/material'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | MatButtonModule, 14 | MatMenuModule, 15 | MatToolbarModule, 16 | MatIconModule, 17 | MatListModule, 18 | MatGridListModule, 19 | MatSidenavModule, 20 | MatCheckboxModule, 21 | MatExpansionModule, 22 | MatFormFieldModule, 23 | MatProgressBarModule, 24 | MatInputModule, 25 | MatProgressSpinnerModule, 26 | MatCardModule 27 | ], 28 | exports: [ 29 | MatButtonModule, 30 | MatInputModule, 31 | MatFormFieldModule, 32 | MatMenuModule, 33 | MatProgressBarModule, 34 | MatListModule, 35 | MatCheckboxModule, 36 | MatProgressSpinnerModule, 37 | MatToolbarModule, 38 | MatExpansionModule, 39 | MatIconModule, 40 | MatGridListModule, 41 | MatSidenavModule, 42 | MatCardModule 43 | ] 44 | }) 45 | export class MaterialModule {} 46 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 6 | import { MaterialModule } from './material.module'; 7 | import { NavComponent } from './nav/nav.component'; 8 | import {RouterModule, Routes} from '@angular/router'; 9 | import { ConfigComponent } from './config/config.component'; 10 | import { InstallComponent } from './install/install.component'; 11 | import { CodeIntroComponent } from './code-intro/code-intro.component'; 12 | import { UsageComponent } from './usage/usage.component'; 13 | 14 | const appRoutes: Routes = [ 15 | {path: 'config', component: ConfigComponent}, 16 | {path: 'install', component: InstallComponent}, 17 | {path: 'code-intro', component: CodeIntroComponent}, 18 | {path: 'usage', component: UsageComponent}, 19 | {path: '**', component: InstallComponent} 20 | ]; 21 | 22 | 23 | 24 | @NgModule({ 25 | declarations: [ 26 | AppComponent, 27 | NavComponent, 28 | ConfigComponent, 29 | InstallComponent, 30 | CodeIntroComponent, 31 | UsageComponent 32 | ], 33 | imports: [ 34 | BrowserModule, 35 | BrowserAnimationsModule, 36 | RouterModule.forRoot(appRoutes), 37 | MaterialModule 38 | ], 39 | providers: [], 40 | bootstrap: [AppComponent] 41 | }) 42 | export class AppModule { } 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yobatis-tour", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^6.1.0", 15 | "@angular/cdk": "~7.0.3", 16 | "@angular/common": "^6.1.0", 17 | "@angular/compiler": "^6.1.0", 18 | "@angular/core": "^6.1.0", 19 | "@angular/forms": "^6.1.0", 20 | "@angular/http": "^6.1.0", 21 | "@angular/material": "^7.0.3", 22 | "@angular/platform-browser": "^6.1.0", 23 | "@angular/platform-browser-dynamic": "^6.1.0", 24 | "@angular/router": "^6.1.0", 25 | "core-js": "^2.5.4", 26 | "hammerjs": "^2.0.8", 27 | "rxjs": "~6.2.0", 28 | "zone.js": "~0.8.26" 29 | }, 30 | "devDependencies": { 31 | "@angular-devkit/build-angular": "~0.8.0", 32 | "@angular/cli": "~6.2.3", 33 | "@angular/compiler-cli": "^6.1.0", 34 | "@angular/language-service": "^6.1.0", 35 | "@types/jasmine": "~2.8.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "@types/node": "~8.9.4", 38 | "codelyzer": "~4.3.0", 39 | "jasmine-core": "~2.99.1", 40 | "jasmine-spec-reporter": "~4.2.1", 41 | "karma": "~3.0.0", 42 | "karma-chrome-launcher": "~2.2.0", 43 | "karma-coverage-istanbul-reporter": "~2.0.1", 44 | "karma-jasmine": "~1.1.2", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.4.0", 47 | "ts-node": "~7.0.0", 48 | "tslint": "~5.11.0", 49 | "typescript": "~2.9.2" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Note 2 | 该项目仅供说明,源码请访问 https://github.com/linbaiye/yobatis-core (核心,本来是支持IDEA和Eclipse) & IDEA UI: https://github.com/linbaiye/yobatis-idea 3 | 4 | # Yobatis简介 5 | 6 | Yobatis是一款基于MybatisGenerator的IDEA插件,在MG的基础上二次开发和封装,快速生成基础的CURD方法;表结构发生变更只需要重新生成即可,Yobatis会保留dao层中手写的方法和xml中自定义的tag。
7 | 插件以Tool Window的形式呈现,只需要简单配置好数据库和文件生成路径即可:
8 | 9 | 10 |
11 | 按照上图配置好单击Generate就可以生成代码:
12 | -----> 13 | 14 |
15 |
16 | 详细介绍请访问Yobatis使用手册:https://linbaiye.github.io/yobatis-tour/ 17 | 18 | 19 | ## 使用生成代码: 20 | 生成代码使用简单,假设Yobatis为表 create table employee(id bigint primary key auto_increment, name char(20), phone char(12)) 生成代码,下面是2个查询示例: 21 | 22 | ``` 23 | // 通过条件查询:select id, name, phone from emloyee where name = 'Alice' and phone is not null 24 | List list = employeeDao.selectList(EmployeeCriteria.nameEqualTo("Alice").andPhoneIsNotNull()); 25 | // 该方法不会返回null 26 | for (Employee employee : list) { 27 | System.out.println(employee.toString()); 28 | } 29 | ``` 30 | 31 | ``` 32 | // select id, name, phone from emloyee where id = 1; 33 | Employee employee = employeeDao.selectOne(1L); 34 | if (employee == null) { 35 | System.out.println('没有id为1的员工.'); 36 | } else { 37 | System.out.println('员工的信息为:' + employee.toString()); 38 | } 39 | ``` 40 | 示例项目: https://github.com/linbaiye/yobatis-sample.git 41 | ## 安装 42 | Yobatis当前只支持本地安装,请下载最新release并通过本地安装方式安装即可。 43 | * 当前只支持Mysql 44 | * java8+ 45 | * idea 144.3600.7+ (15年中以后的release应该都可以) 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "yobatis-tour": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/yobatis-tour", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "aot": true, 45 | "extractLicenses": true, 46 | "vendorChunk": false, 47 | "buildOptimizer": true 48 | } 49 | } 50 | }, 51 | "serve": { 52 | "builder": "@angular-devkit/build-angular:dev-server", 53 | "options": { 54 | "browserTarget": "yobatis-tour:build" 55 | }, 56 | "configurations": { 57 | "production": { 58 | "browserTarget": "yobatis-tour:build:production" 59 | } 60 | } 61 | }, 62 | "extract-i18n": { 63 | "builder": "@angular-devkit/build-angular:extract-i18n", 64 | "options": { 65 | "browserTarget": "yobatis-tour:build" 66 | } 67 | }, 68 | "test": { 69 | "builder": "@angular-devkit/build-angular:karma", 70 | "options": { 71 | "main": "src/test.ts", 72 | "polyfills": "src/polyfills.ts", 73 | "tsConfig": "src/tsconfig.spec.json", 74 | "karmaConfig": "src/karma.conf.js", 75 | "styles": [ 76 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 77 | "src/styles.css" 78 | ], 79 | "scripts": [], 80 | "assets": [ 81 | "src/favicon.ico", 82 | "src/assets" 83 | ] 84 | } 85 | }, 86 | "lint": { 87 | "builder": "@angular-devkit/build-angular:tslint", 88 | "options": { 89 | "tsConfig": [ 90 | "src/tsconfig.app.json", 91 | "src/tsconfig.spec.json" 92 | ], 93 | "exclude": [ 94 | "**/node_modules/**" 95 | ] 96 | } 97 | } 98 | } 99 | }, 100 | "yobatis-tour-e2e": { 101 | "root": "e2e/", 102 | "projectType": "application", 103 | "architect": { 104 | "e2e": { 105 | "builder": "@angular-devkit/build-angular:protractor", 106 | "options": { 107 | "protractorConfig": "e2e/protractor.conf.js", 108 | "devServerTarget": "yobatis-tour:serve" 109 | }, 110 | "configurations": { 111 | "production": { 112 | "devServerTarget": "yobatis-tour:serve:production" 113 | } 114 | } 115 | }, 116 | "lint": { 117 | "builder": "@angular-devkit/build-angular:tslint", 118 | "options": { 119 | "tsConfig": "e2e/tsconfig.e2e.json", 120 | "exclude": [ 121 | "**/node_modules/**" 122 | ] 123 | } 124 | } 125 | } 126 | } 127 | }, 128 | "defaultProject": "yobatis-tour" 129 | } -------------------------------------------------------------------------------- /src/app/usage/usage.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import {MethodUsage} from '../method-usage'; 3 | 4 | @Component({ 5 | selector: 'app-usage', 6 | templateUrl: './usage.component.html', 7 | styleUrls: ['./usage.component.css'] 8 | }) 9 | export class UsageComponent implements OnInit { 10 | 11 | methodUsageList: MethodUsage[] = [ 12 | new MethodUsage('int insert(BaseEmployee record)', '插入一条记录', 13 | '调用该方法向表中插入一条记录,如表为自增主键且record中对应主键的field为null,该方法会将新主键设置到record对应的field中;如表为自增主键且record中对应主键的field不为null,则将对应的主键插入表中。', 14 | '返回1若插入成功。', ` 15 | Employee employee = new Employee(); 16 | employee.setName('Alice'); 17 | employee.setPhone('123'); 18 | employeeDao.insert(employee); 19 | System.out.println('新纪录的id是:' + employee.getId()); 20 | 21 | employee = new Employee(); 22 | employee.setName('Bob'); 23 | employee.setPhone('124'); 24 | employee.setId(2L); 25 | employeeDao.insert(employee); // 新记录的id(主键)为2`), 26 | new MethodUsage('Employee selectOne(Long pk)', '通过主键查询一条记录', '根据主键查询记录。', 27 | '返回记录对应的对象或者null。', ` 28 | Employee employee = employeeDao.selectOne(1L); 29 | if (employee == null) { 30 | System.out.println('没有id为1的员工.'); 31 | } else { 32 | System.out.println('员工的信息为:' + employee.toString()); 33 | }`), 34 | new MethodUsage('Employee selectOne(EmployeeCriteria criteria)', '通过criteria查询一条记录', '通过criteria查询一条记录。', 35 | '返回记录对应的对象或者null,若查询条件命中多条记录则抛出异常。', ` 36 | try { 37 | Employee employee = employeeDao.selectOne(EmployeeCriteria.nameEqualTo("Alice")); 38 | if (employee == null) { 39 | System.out.println("没有名字为Alice的记录"); 40 | } else { 41 | System.out.println("找到一条名字为Alice的记录:", employee.toString()); 42 | } 43 | } catch (TooManyResultsException e) { 44 | System.out.println("找到多条名字为Alice的记录"); 45 | }`), 46 | new MethodUsage('List selectList(EmployeeCriteria criteria)', '通过criteria查询多条记录', '通过criteria查询多条记录。', 47 | '返回查询到的记录,或者一个空List如果没有查询到相应记录。', ` 48 | // where name = 'Alice' and phone is not null; 49 | List list = employeeDao.selectList(EmployeeCriteria.nameEqualTo("Alice").andPhoneIsNotNull()); 50 | // 该方法不会返回null 51 | for (Employee employee : list) { 52 | System.out.println(employee.toString()); 53 | } 54 | 55 | // where (name = 'Alice' and phone is not null) or (name = 'Bob') 56 | List list = employeeDao.selectList(EmployeeCriteria.nameEqualTo("Alice").andPhoneIsNotNull() 57 | .or() // <-加入or 58 | .andNameEqualTo("Bob")); 59 | for (Employee employee : list) { 60 | System.out.println(employee.toString()); 61 | } 62 | 63 | // select id, name, phone from employee where id is not null limit 10 offset 1 order by name asc, phone desc for update 64 | List list = employeeDao.selectList(EmployeeCriteria.idIsNotNull() 65 | .setLimit(10L) // 最多10条记录 66 | .setOffset(1L) // offset为1 67 | .ascOrderBy("name") // 通过name字段做asc排序, 参数为数据库中的字段名 68 | .descOrderBy("phone") // 若name相同则通过phone desc排序, 参数为数据库中的字段名 69 | .setForUpdate(true) // 设置for update, 小心使用 70 | ); 71 | for (Employee employee : list) { 72 | System.out.println(employee.toString()); 73 | } 74 | `), 75 | new MethodUsage('int count(EmployeeCriteria criteria)', '统计符合criteria的记录数量', '通过criteria统计记录数量。', 76 | '返回统计数量。', ` 77 | int count = employeeDao.count(EmployeeCriteria.phoneIsNotNull()); 78 | System.out.println("找到" + count + "电话不为空的记录");`), 79 | new MethodUsage('int update(BaseEmployee record)', '通过主键更新记录', '该方法将record中不为null的field更新到对应主键的记录中', 80 | '返回1如果更新成功,0如果该记录不存在', ` 81 | Employee employee = new Employee(); 82 | employee.setId(2L); 83 | // 只更新phone, name保持现状 84 | employee.setPhone("156"); 85 | int count = employeeDao.update(employee); 86 | if (count == 1) { 87 | System.out.println("更新成功。"); 88 | } else { 89 | System.out.println("没有找到id为2的记录"); 90 | }`), 91 | new MethodUsage('int update(BaseEmployee record, EmployeeCriteria criteria)', '通过criteria批量更新记录', 92 | '该方法将record中不为null的field更新到criteria选中的记录。', 93 | '返回被更新记录数量。', ` 94 | Employee employee = new Employee(); 95 | employee.setPhone("156"); 96 | // update employee set phone = '156' where id <= 4 97 | int count = employeeDao.update(employee, EmployeeCriteria.idLessThanOrEqualTo(4L)); 98 | System.out.println("成功更新" + count + "条记录");`), 99 | new MethodUsage('int delete(Long pk)', '删除主键对应的记录', '删除主键对应的记录。', 100 | `返回1如果删除成功,0如果没有该记录。`, ` 101 | // delete from employee where id = 1 102 | int count = employeeDao.delete(1L); 103 | if (count == 1) { 104 | System.out.println("删除成功"); 105 | } else { 106 | System.out.println("没有找到该记录"); 107 | }`), 108 | new MethodUsage('int delete(EmployeeCriteria criteria)', '通过条件批量删除', '批量删除,小心使用。', 109 | '被删除记录数量。', ` 110 | // delete from employee where id is not null 111 | // 务必保证这是你想要的。 112 | int count = employeeDao.delete(EmployeeCriteria.idIsNotNull()); 113 | System.out.println("一共删除" + count + "条记录");`)]; 114 | 115 | constructor() { } 116 | 117 | ngOnInit() { 118 | } 119 | 120 | } 121 | --------------------------------------------------------------------------------