Atitit code 范例 example
code 范例 example 更好一些,将最佳实践融入其中。。
目录
第一节 Atitit http rest php workman api rsps
第二节 Atitit recv https req post code 接受https请求 nodejs
第四节 Db acc code mybatis jsdbtmeplte hbnt
第四节 Nodejs https http post json
第一节 ExcelUtil export json list
Springboot test,,springboot lazy load
/miniCodePrj/src/main/java/sprbtPKg/Application.java
Php rest api
public static void main(String[] args) {
// sqlSessionFactory=getSqlSessFctry(dataSource, UserMapper.class);
// tk_ini(sqlSessionFactory);
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/mysql?allowMultiQueries=true"; // 创建一个表示数据库路径的字符串
String username = "root"; // 创建一个表示数据库用户名的字符串
String password = ""; // 创建一个表示数据库密码的字符串
DriverManagerDataSource dataSource = new DriverManagerDataSource(url, username, password);
String tableName = "user";
Map<String, Object> parameters_map = new HashMap<String, Object>(3);
parameters_map.put("id", 123);
parameters_map.put("first_name", "aaa");
int i = insert(dataSource, tableName, parameters_map);
System.out.println(i);
System.out.println("f");
}
private static int insert(DriverManagerDataSource dataSource, String tableName,
Map<String, Object> parameters_map) {
SimpleJdbcInsert SimpleJdbcInsert1 = new SimpleJdbcInsert(dataSource).withTableName(tableName);
Set st = parameters_map.keySet();
List<String> columnNames = new ArrayList<String>();
columnNames.addAll(st);
SimpleJdbcInsert1.setColumnNames(columnNames);
// SimpleJdbcInsert1.usingColumns(columnNames)
int i = SimpleJdbcInsert1.execute(parameters_map);
return i;
}
Hibernate code demo
MybatisTest
String uri=rq.getRequestURI();
String query=rq.getQueryString();
String newUrl = targetHost+uri+"?"+query;
CloseableHttpResponse response =HttpClients.createDefault().execute(new HttpGet(newUrl)) ;
return EntityUtils.toString(response.getEntity(), "UTF-8");
Atitit php http post jspn code
Nodejs.http post json
const args = process.argv.slice(2)
//var param=args[0];
var param = (new Buffer(args[0], 'base64').toString())
//var param={};
var fs = require('fs');
var cfgObj = JSON.parse(fs.readFileSync('a_cfg.json') + '');
console.log(cfgObj)
var $url = cfgObj['url'];
//"https://7398c09d63b0.ngrok.io/v1/api/order/build";
console.log($url);
console.log(param);
var prmObj = JSON.parse(param);
const axios = require('axios')
//zwajye cyifen json hesh txt...zosh yaosi obj shg json ,zo head add app/json,,beir txt ..
axios
.post($url, prmObj)
.then(res => {
// console.log(`statusCode: ${res.statusCode}`) //statusCode: undefined
console.log(res.data);
// console.log(res)
})
.catch(error => {
console.error(error)
})
Atitit 读取文件并处理
Ticyiutxt.php
<?php
$f="d:\ppl";
$con = file($f );
$data = array();
foreach($con as $line) {
$posStart=stripos($line, "——");
if($posStart){
// $line = trim($line);
$name= substr($line, $posStart);
echo $name;
}else
{
echo $line;
}
}
Ref
Atitit mybatis helloworld