$userName=$_GET['userName']?$_GET['userName']:''if($isYoung){
$data=['user_name'=>$userName]
$db->insert($data,$table)
}
第二种:属性采用驼峰,传参与mysql一致
$userName=$_GET['user_name']?$_GET['user_name']:''if($isYoung){
$data=['user_name'=>$userName]
$db->insert($data,$table)
}
手敲的,给个辛苦分吧。。。package test
import java.util.ArrayList
import java.util.List
public class Test {
public static void main(String[] args) {
//testing for data base column-key to java field
String[] dbKeys = {"id", "user_age", "user_addr_"}
Test t = new Test()
t.convertToJava(dbKeys)
System.out.println("-----------------------------------")
//testing for Java field to data base column-key
String javaFieldNames[] = {"id","userAge","userHomeAddr"}
t.getDBKey(javaFieldNames)
}
/*
* Java field to data base column-key
*/
private void getDBKey(String... javaFieldNames){
if(javaFieldNames != null && javaFieldNames.length > 0){
for(String name : javaFieldNames){
StringBuffer buffer = new StringBuffer()
char[] array = name.toCharArray()
List<Integer> insertIndexes = new ArrayList<>()
for(int i=0i<array.lengthi++){
Character c = array[i]
if(i != 0 && Character.isUpperCase(c)){
insertIndexes.add(i)
}
}
if(insertIndexes.size() > 0){
int flag = 0
for(int j=0j<insertIndexes.size()j++){
String word = toLowercase4FirstLetter(name.substring(flag, insertIndexes.get(j)))
buffer.append(word).append("_")
flag = insertIndexes.get(j)
}
String last = toLowercase4FirstLetter(name.substring(flag))
buffer.append(last)
System.out.println(buffer.toString())
} else {
System.out.println(name)
}
}
}
}
private String toLowercase4FirstLetter(String word){
if(word != null && word.length() > 0){
String firstLetter = word.substring(0,1)
String others = word.substring(1)
return firstLetter.toLowerCase() + others
}else{
return ""
}
}
/*
* data base column-key to java field
*/
public void convertToJava(String... dbKeys) {
if(dbKeys != null && dbKeys.length > 0){
for(String key : dbKeys){
String[] words = key.split("_")
String result = toUppercase4FirstLetter(words)
System.out.println(result)
}
}
}
private String toUppercase4FirstLetter(String... words){
StringBuffer buffer = new StringBuffer()
if(words != null && words.length > 0){
for(int i=0i<words.lengthi++){
String word = words[i]
String firstLetter = word.substring(0, 1)
String others = word.substring(1)
String upperLetter = null
if(i != 0){
upperLetter = firstLetter.toUpperCase()
} else {
upperLetter = firstLetter
}
buffer.append(upperLetter).append(others)
}
return buffer.toString()
}
return ""
}
}
(1)按下图,
点击view-----选择tool
windows----------选择database并点击
(2)d出Database窗口,点击加号------------选择data
source---------------选择想添加的数据库并点击
(3)d出DataSources
and
Drivers窗口,分别填写画圈的方框。
host-----写ip地址
Database-------写数据库名称
user-------写账号
Password------写密码
填好之后,可以点击一下test
Connection,如果连接成功,那么test
Connection按钮的右边会显示
一句话提示连接成功。连接成功后就点击右下角的OK。
(4)点击OK后出现如下结果,Database下出现一个数据库。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)