Addition, deletion of javascript object attributes, json object and string conversion methods, etc.
1:Dynamicly add object properties var obj = new Object(); console.log (obj.username); obj.username = “haha”; console.log (obj.username); //undefined //haha is represented by “[]“. Written as obj[“username”] = “haha”; var obj = new Object(); console.log (obj.username); obj[“username”] = “haha”; console.log (obj.username); //undefined //haha You can also define it directly var obj = {username:”haha”, password:”123″}; console.log(obj.username); console.log(obj.password); //haha //123 2:Delete attributes,Usedelete var obj = new Object(); obj[“username”] = “haha”; console.log (obj.username); delete obj.username; console.log (obj.username); //haha //undefined 3: Modify the original attributes and add new attributes var json = { “age”:24, “name”:”haha” }; //ModifyJsonagevalue json[“age”] = 30; console.log(json.age); //30 //IncreaseJsonsexvalue json[“sex”] = “w”; console.log(json.sex); //w 4: JsonObject and JsonString conversion JSON.parse(jsonstr); //Can convertjsonstring into jsonObject var jsObj = {}; jsObj.testArray = [1,2,3]; jsObj.name = ‘CSS3’; jsObj.date = ‘2017’; console .log(jsObj) console.log(typeof(jsObj));var str = JSON.stringify(jsObj); var str1 = JSON.parse(str); console.log (str) console.log(typeof(str)); console.log(str1) console.log(typeof(str1));//Object {testArray: Array[3 ], name: “CSS3”, date: “2017”}//object// {“testArray”:[1,2,3],”name”:”CSS3″,”date”: “2017”}// string//Object {testArray: Array[3], name: “CSS3”, date: “2017”}// object JSON.stringify(jsonobj); //Can convertjson objects into json String var jsObj = {}; jsObj.testArray = [1,2,3]; jsObj.name = ‘CSS3’; jsObj.date = ‘2017’; console .log(jsObj) console.log(typeof(jsObj));var str = JSON.stringify(jsObj); console.log(str) console.log(typeof(str ));//Object {testArray: Array[3], name: “CSS3”, date: “2017”}// object// {“testArray”:[1,2, 3],”name”:”CSS3″,”date”:”2017″}//string
Addition, subtraction, multiplication and division in java
Several uses of DecimalFormat! http://blog.sina.com.cn/s/blog_4fcb75bd01008bz7.html About common methods of java.math.BigDecimal classhttp://www.2cto.com/kf/201204/128096 .html Precision issues with float operations in javahttp://www.jspspace.com/service/Art-3177-5.html Issues with double operations in javahttp:// www.blogjava.net/mphome/archive/2007/12/10/166783.html An exception that BigDecimal is not divisible by java.lang.ArithmeticException: Non-terminating decimal expansionhttp://hi.baidu.com/yanghlcn/item/0698ee1cee21bf0fe65c36b7 Non-terminating decimal expansion; no exact http://hi.baidu.com/melove1006/item/2786b87cb192fb326cc37c72 2011-10-19 19:14 Format numbers using DecimalFormat http://hi.baidu.com/ihsauqaxblbdmwq/item/87b4c8e94c53e4206cabb840
Java time addition and subtraction_Let’s talk about several common operations on dates in Java—value acquisition, conversion, addition, subtraction, and comparison
In the development process of Java, it is inevitable to get entangled with the Date type,I am going to summarize the date-related operations frequently used in the project,JDK version 1.7,If it can help everyone save a few minutes to get up and move, #xff0c; Go make a cup of coffee , it will be great, Hehe. Of course, “I only provide feasible solutions” and do not guarantee best practices. Discussions are welcome. 1. Date value In the era of the old version of JDK, there were many codes that used the java.util.Date class to obtain date values. However, Since the Date class is not convenient for internationalization, in fact, starting from JDK1.1, it is more recommended to use the java.util.Calendar class for time and date processing. The operations of the Date class will not be introduced here – let us go straight to the topic – how to use the Calendar class to obtain the current date and time. Since Calendar’s constructor method is protected, we will create a Calendar object through the getInstance method provided in the API. 1 //There are multiple overloaded methods to create Calendar objects 2 Calendar now = Calendar.getInstance(); //Default 3 //Specify time zone and…
Java operations on mysql database (connection, addition, deletion, modification and query)
java operation on mysql database(connection,add, delete, modify) environment:myeclipse 2014 + tomcat + mysql ( Navicat for mysql) 1. Implement query: package com.mysql;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement; public class DBChaxun {private static final String url = ; “jdbc:mysql://localhost:3306/web”;private static final String user = “root”;private static final String password = “root”;public static void main(String[] args ) throws ClassNotFoundException, SQLException {//1. Load the driver (mysql) Class.forName(“com.mysql.jdbc.Driver”); //2. Get the database connection Connection conn = DriverManager.getConnection(url , user, password); //3. Operate the database through database connection , to implement addition, deletion, modification and query Statement stmt = conn.createStatement(); //Create statement object ResultSet rs = stmt.executeQuery (“select name, age from info”); //(1) Implement the query function , and return the resultset object //4. Get the data in the resultset object while(rs.next()){System.out. println(rs.getString(“name”)+rs.getInt(“age”));}}} 2.Implementdeletion: packagecom.mysql;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassDBDelete{privatestaticfinalStringurl=”jdbc:mysql://localhost:3306/web”;privatestaticfinalStringuser=”root”;privatestaticfinalStringpassword=”root”;publicstaticvoidmain(String[]args)throwsClassNotFoundException,SQLException{//1.Loadthedriver(mysql)Class.forName(“com.mysql.jdbc.Driver”);//2.GetthedatabaseconnectionConnectionconn=DriverManager.getConnection(url,user,password);//3.Operatethedatabasethroughdatabaseconnection,toimplementaddition,deletion,modificationandqueryStatementstmt=conn.createStatement();//CreatestatementobjectStringsql=”deletefrominfowherename='lry'”;//stmt.execute(sql);//Directlyinsertdataintothedatabasetableintrows=stmt.executeUpdate(sql);System.out.println(“Thenumberofrowsaffectedis:”+rows);}} 3. Implement added (insert): package com.mysql;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException; import java.sql.Statement;public class DBInsert {private static final String url = “jdbc:mysql://localhost:3306/web”;private static final String user = “root”;private static final String password = “root”; public static void main(String[] args) throws ClassNotFoundException, SQLException {//1. Load driver (mysql) Class.forName(“com.mysql.jdbc.Driver”); //2. Get the connection to the database Connection conn = DriverManager.getConnection(url, user, password); //3. Operate the database through the database connection , to implement…
Let’s talk about several common operations on dates in Java—value acquisition, conversion, addition, subtraction, and comparison.
In the development process of Java, it is inevitable to get entangled with the Date type,I am going to summarize the date-related operations frequently used in the project,JDK version 1.7,If it can help everyone save a few minutes to get up and move, #xff0c; Go make a cup of coffee , it will be great, Hehe. Of course, “I only provide feasible solutions” and do not guarantee best practices. Discussions are welcome. 1. Date value In the era of the old version of JDK, there were many codes that used the java.util.Date class to obtain date values. ,However, since the Date class is not convenient for internationalization, in fact, starting from JDK1.1, it is more recommended to use the java.util.Calendar class for time and date processing. The operations of the Date class will not be introduced here – let us go straight to the topic – how to use the Calendar class to obtain the current date and time. Since Calendar’s constructor method is protected, we will create a Calendar object through the getInstance method provided in the API. 1 //There are multiple overloaded methods to create Calendar objects2 Calendar now = Calendar.getInstance(); //Default3 // Specify time zone and region,…
PHP realizes data display, addition, modification, deletion and query of text database
PHP implements the five basic operations of data display, addition, modification, deletion and query of text database I use a guestbook program as an example to explain how PHP implements the five basic operations of data display, addition, modification, deletion, and query on text databases. This text database has 10 fields in total: customer IP, speaking time, customer name, customer EMAIL, customer homepage address, message emoticon picture name, customer QQ, customer image picture, message content, and administrator reply content. 1. Add data program segments. $date=date(“Y-m-d H:i:s”);//Get the system time $ip = $HTTP_SERVER_VARS[REMOTE_ADDR]; //Get the IP address of the speaker $text=encode($gb_text);//Remove the spaces after the message content. $fp=fopen(“gb.dat”,”a”);//Open the gb.dat text file in write-only mode, with the file pointer pointing to the end of the file. $str =$ip.”|”.$date.”|”.$gb_name.”|”.$gb_email.”|”.$gb_home.”|”.$face.”|”.$gb_qq.”| “.$head.”|”.$text.”|”.$reply.”\n”;//Assign the data of all messages to the variable $str. The purpose of “|” is to be used for data segmentation in the future. Data break symbol. fwrite($fp,$str);//Write data to file fclose($fp);//Close the file showmessage(“Message successful!”,”index.php”,”3″);//The message is successful and will automatically return to the main interface after 3 seconds. Among them, $gb_name, $gb_email, $gb_home, $face, $gb_qq, $head, $gb_text, and $reply are the data passed from the speech form. 2. Data display program…
JS acquisition, addition, and deletion operations for HTML tag select_javascript skills-js tutorial
The code is as follows: (empty) 1 The code is as follows: //Get the html controlvar select = document.getElementsByName(“aaa”)[0]; select.selectedIndex = index; //Create a new Option objectnew Option(text,value) new option(text,value,defaultSelected,selected text: string, specifying the text attribute of the option object (that is, the text between ) value: String, specifies the value attribute of the option objectdefaultSelected: Boolean value, specifies the defaultSelected attribute of the option objectselected: Boolean value, specifies the selected attribute of the option object // Add Option to select select.add(new Option(text,value)) //Deleteselect.options.remove(index) //Delete all at onceselect.length = 0;
PHP implements the five basic operations of data display, addition, modification, deletion and query on text database – PHP tutorial
PHP implements the five basic operations of data display, adding, modifying, deleting and querying text databases This text database has a total of 9 fields: private $bankid; //Bank ID private $bankname; //Bank name private $bankimg; //Bank picture private $bankarea; //Coverage area private $bankcard; //Card types accepted private $banklimit; //Payment limit private $bankpasswd; //Transaction password private $banknote; //Bank information remarks private $bankmiss; //Other information content of the bank. <?php /** php implements data display, addition, modification, deletion and query of text database Five basic operation methods. This text database has a total of 9 fields: private $bankid; //Bank ID private $bankname; //Bank name private $bankimg; //Bank picture private $bankarea ; //Covered area private $bankcard; //Accepted card types private $banklimit; //Payment limit private $bankpasswd; //Transaction password private $banknote; //Bank information Remarks private $bankmiss; //Other information about the bank. @abstract TxtDB store @access public @author [email protected] */ class TxtDB { private $bankid; //Bank ID private $bankname; //Bank name private $bankimg; //Bank picture private $bankarea; //Coverage area private $bankcard; // Accepted card types private $banklimit; //payment limit private $bankpasswd; //transaction password private $banknote; //bank information notes private $bankmiss; //other bank information public function __construct() { $bankid = “”; //Bank ID $bankname = “”; //Bank…
phpDOMDocument application example (XML creation, addition, deletion, modification)
<?php $xmlpatch = ‘index.xml’; $_id = ‘1’; $_title = ‘title1’; $_cOntent= ‘content1’; $_author = ‘author1’; $_sendtime = ‘time1’; $_htmlpatch = ‘1.html ‘; $doc = new DOMDocument(‘1.0’, ‘utf-8’); $doc -> formatOutput = true; $root = $doc -> createElement_x(‘root’); //New node $index = $doc -> createElement_x(‘index’);//New node $url = $doc -> createAttribute(‘url’);//New attribute $ patch = $doc -> createTextNode($_htmlpatch);//Create a new TEXT value $url -> appendChild($patch);//Set the $patch text to the value of the $url attribute $id = $ doc -> createAttribute(‘id’); $newsid = $doc -> createTextNode($_id); $id -> appendChild($newsid); $title = $doc -> createAttribute (‘title’); $newstitle = $doc -> createTextNode($_title); $title -> appendChild($newstitle); $cOntent= $doc -> createTextNode($_content) ;//Node value $author = $doc -> createAttribute(‘author’); $newsauthor = $doc -> createTextNode($_author); $author -> appendChild($newsauthor) ; $sendtime = $doc -> createAttribute(‘time’); $newssendtime = $doc -> createTextNode($_sendtime); $sendtime -> appendChild($newssendtime); $index -> appendChild($id);//Set $id as an attribute of the index node, the following is similar to $index -> appendChild($title); $index -> appendChild($content) ; $index -> appendChild($url); $index -> appendChild($author); $index -> appendChild($sendtime); $root -> appendChild($ index);//Set index as the root byte point $doc -> appendChild($root);//Set root as the append node $doc -> save($xmlpatch);//Save the file echo $xmlpatch . ‘ has create success’; ?> 2. Add.php…
Simple usage example code of DOMDocument in php (XML creation, addition, deletion, modification)_PHP tutorial
There are four files in total, which have four functions: create, add, delete, and modify. The variables are all hard-coded. You can use $_POST instead to receive them//index.php creation function The code is as follows: <?php $xmlpatch = ‘index.xml’; $_id = ‘1’; $_title = ‘title1’; $_cOntent= ‘content1’; $_author = ‘author1’; $_sendtime = ‘time1’; $_htmlpatch = ‘1.html’; jb51.net$doc = new DOMDocument(‘1.0’, ‘utf-8’); $doc -> formatOutput = true; jb51.net$root = $doc -> createElement(‘root’);//New nodejb51.net$index = $doc -> createElement(‘index’);//New nodejb51.net$url = $doc -> createAttribute(‘url’);//New attribute$ patch = $doc -> createTextNode($_htmlpatch);//New TEXT value$url -> appendChild($patch);//Set the $patch text to the value of the $url attributejb51.net$ id = $doc -> createAttribute(‘id’); $newsid = $doc -> createTextNode($_id); $id -> appendChild($newsid); jb51.net$title = $doc -> createAttribute(‘title’); $newstitle = $doc -> createTextNode($_title); $title -> appendChild($newstitle); jb51.net$cOntent= $doc -> createTextNode($_content);//Node valuejb51.net$author = $doc -> createAttribute(‘author’); $newsauthor = $doc -> createTextNode($_author); $author -> appendChild($newsauthor); jb51.net$sendtime = $doc -> createAttribute(‘time’); $newssendtime = $doc -> createTextNode($_sendtime); $sendtime -> appendChild($newssendtime); jb51.net$index -> appendChild($id);//Set $id as an attribute of the index node, the following is similar to $index -> appendChild($title); $index -> appendChild($content); $index -> appendChild($url); $index -> appendChild($author); $index -> appendChild($sendtime); jb51.net$root -> appendChild($index);//Set index to the root byte pointjb51.net$doc -> appendChild($root);/ /Set…