Monthly Archives: 9月 2017

「PostgreSQL入門」カラム型の変更、制約の追加方法

1.カラム型の変更
ALTER TABLE SAMPLE_TBL ALTER COLUMN S_NO TYPE VARCHAR(2)

2.制約の追加
ALTER TABLE SAMPLE_TBL ALTER COLUMN S_NO SET NOT NULL

PostgreSQLの外部キー制約を追加、削除する方法

1.追加
ALTER TABLE EMPLOYEE_MANAGE ADD FOREIGN KEY (USER_ID) REFERENCES USER_CFT(USER_ID)
ON
DELETE CASCADE;

2.表示
SELECT
*
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = ‘FOREIGN KEY’
AND TABLE_NAME = ‘EMPLOYEE_MANAGE’;

3.削除
ALTER TABLE EMPLOYEE_MANAGE DROP CONSTRAINT USER_ID

「jQuery入門」$.extend(src)の使い方

1.$.extend(src)
$.extend({ welcome:function(){alert(‘welcome’);} });

2.$.fn.extend(src)
$.fn.extend({ welcome:function(){alert(‘welcome’);} });

3.$.extend({net:{}});
$.extend($.net,{ welcome:function(){alert(‘welcome’);} })

「JavaScript入門」配列の重複する要素を削除するコード

JSコード
//配列の重複要素
function uniqueElemntFunc(data) {
data = data || [];
var a = {};
for (var i = 0; i < data.length; i++) {
var v = data[i];
if (typeof (a[v]) == ‘undefined’) {
a[v] = 1;
}
};
data.length = 0;
for (var i in a) {
data[data.length] = i;
}
return data;
}

var stack = new Array();
for (var i = 0; i < rowCount; i++) {
stack.push(“test”);
}

//メソッドを呼び出す
var noRepeatStack = uniqueElemntFunc(stack);

「PHP入門」curlでcookieを保存するサンプル

PHPコード
<?php
$curl = curl_init();
$url = ‘http://xxx/login’;
$data = array(
‘username’=>’testuser’,
‘password’=>’12345678’
);
$cookie = tempnam(‘./temp’,’cookie’);
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_POST,count($data));
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie);
ob_start();
curl_exec($curl);
$result = ob_get_contents();
ob_end_clean();
curl_close($curl);

「JavaScript開発」複数のスペースをひとつのカンマで置き換えるコード

JavaScriptコード
function doStrRepKanma(str){
str=trim(str);
var strarry=unique(str.split(“,”));
str=strarry.join(“,”);
str=str.replace(/,/ig,”,”);
str=str.replace(/[^0-9,]*/ig,””);
str=str.replace(new RegExp(‘,+’,”gm”),’,’);
if (str.substr(0,1)==’,’) str=str.substr(1);
var reg=/,$/gi;
str=str.replace(reg,””);
return str;
}

org.springframework.beans.propertyeditors.PropertiesEditorの使い方

1.IntegerEditorクラス
import org.springframework.beans.propertyeditors.PropertiesEditor;
public class IntegerEditor extends PropertiesEditor {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (text == null || text.equals(“”)) {
text = “0”;
}
setValue(Integer.parseInt(text));
}

@Override
public String getAsText() {
return getValue().toString();
}
}

2.FloatEditorクラス
import org.springframework.beans.propertyeditors.PropertiesEditor;

public class FloatEditor extends PropertiesEditor {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (text == null || text.equals(“”)) {
text = “0”;
}
setValue(Float.parseFloat(text));
}

@Override
public String getAsText() {
return getValue().toString();
}
}

3.LongEditorクラス
import org.springframework.beans.propertyeditors.PropertiesEditor;
public class LongEditor extends PropertiesEditor {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (text == null || text.equals(“”)) {
text = “0”;
}
setValue(Long.parseLong(text));
}

@Override
public String getAsText() {
return getValue().toString();
}
}

「Spring MVC」@PathVariableアノテーションを使用するサンプル

1.Javaコード
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PathVariableExampleController {

/**
* @PathVariable Example:
*
*/
@RequestMapping(“/cft/lijia/{sitePrefix}/{language}/document/{id}/{naturalText}”)
public String documentView(Model model,
@PathVariable(value = “sitePrefix”) String sitePrefix,
@PathVariable(value = “language”) String language,
@PathVariable(value = “id”) Long id,
@PathVariable(value = “naturalText”) String naturalText) {

model.addAttribute(“sitePrefix”, sitePrefix);
model.addAttribute(“language”, language);
model.addAttribute(“id”, id);
model.addAttribute(“naturalText”, naturalText);

String documentName = “Java tutorial for Studyers”;
if(id == 8108) {
documentName = “Spring MVC for Studyers”;
}

model.addAttribute(“documentName”, documentName);

return “documentView”;
}
}

2.JSPコード
/WEB-INF/pages/documentView.jsp
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>${documentName}</title>
</head>
<body>
<h3>${documentName}</h3>
Site Prefix: ${sitePrefix}
<br> Language: ${language}
<br> ID: ${id}
<br> Natural Text: ${naturalText}
<br>

</body>
</html>

URLの確認
http://localhost:8080/HelloSpringMVC/cft/lijia/default/en/document/8108/spring-mvc-for-beginners

「Spring MVC」InitBinderでDate型パラメータを設定するコード

Javaコード
//the parameter was converted in initBinder
@RequestMapping(“/date”)
public String date(Date date){
System.out.println(date);
return “hello”;
}

//At the time of initialization,convert the type “String” to type “date”
@InitBinder
public void initBinder(ServletRequestDataBinder binder){
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat(“yyyy-MM-dd”),
true));
}

「PoStgreSQL入門」substr()で文字列の一部を取得する

SQL構文
select substr(‘1234’,0,3) as cft

postgreSQLの場合、結果:12
Oracleの場合、結果:12
MySQLの場合、結果:空白

1 / 612345...最後 »