Automatically convert user submitted forms to SQL using Form-sql-builder-mysql
Maven Dependency
<dependency> <groupId>org.crazycake</groupId> <artifactId> Form-sql-builder-mysql</artifactid> <version>1.0.0-RELEASE</version></dependency>
Quick Start
STEP 1. Create a rule file
Under Classpath, create a folder called Formsqlrules, which is created under this folder Global.json
{"Global": [{"Field": "String:*", "Op": "Like", "rel": "and"},{"field": "*:*", "op": "=", "rel": "and"}]}
STEP 2. Create a test with a PO class
public class Person {private Integer activestatus;private string name;private integer age;private string city;public perso N (string name, Integer age, String city, Integer activestatus) {this.name = Name;this.age = Age;this.city = City;this.activ Estatus = Activestatus;} Public Integer Getactivestatus () {return activestatus;} public void Setactivestatus (Integer activestatus) {this.activestatus = Activestatus;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public Integer Getage () {return age;} public void Setage (Integer age) {this.age = age;} Public String getcity () {return city;} public void Setcity (String city) {this.city = city;}}
STEP 3. Call Formsqlbuilder
person form = new Person ("Jack", "$", "NY", 1); Formsqlbuilder B = new Formsqlbuilder (form, "global"); B.addlimit (1, 20); Sqlandparams s = b.build (); System.out.println (S.getsql ()); for (Object V:s.getparams ()) {System.out.println (v);}
Console output
SELECT * from who WHERE name like? And city like? and Active_status =? and age =? LIMIT 0,20jackny136
More specific about the
- Syntax and optional values for rules
- Use of wildcard characters
- Scope Query
- Group queries
- Add limit
- Add sort
- In query
See the GitHub website
Automatically convert user submitted forms to SQL using Form-sql-builder-mysql