風(fēng)人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評(píng)論 - 56, 引用 - 0
          數(shù)據(jù)加載中……

          2016年11月8日

          Spring boot+Spring Security 4配置整合實(shí)例

          http://blog.csdn.net/code__code/article/details/53885510

          1. 使用Spring Security管理用戶身份認(rèn)證、登錄退出

          2. 用戶密碼加密及驗(yàn)證

          3. 采用數(shù)據(jù)庫的方式實(shí)現(xiàn)Spring Securityremember-me功能

          4. 獲取登錄用戶信息。

          5.使用Spring Security管理url和權(quán)限

          posted @ 2018-03-19 21:02 風(fēng)人園 閱讀(318) | 評(píng)論 (0)編輯 收藏

          spring security 參數(shù)配置

               摘要:         // 自定義登錄頁面          http.csrf().disable().formLogin().loginPage("/login")  //指定登錄頁的路徑&n...  閱讀全文

          posted @ 2018-03-19 20:33 風(fēng)人園 閱讀(434) | 評(píng)論 (0)編輯 收藏

          spring quartz 串行配置

          <bean id="jobDetail7"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

                             <propertyname="targetObject" ref="billingBillTask"></property>

                             <propertyname="targetMethod" value="executeInternal" />

                             <propertyname="concurrent" value="false" />

                   </bean>

                   <beanid="billingBillTask"class="com.dangdang.tms.job.schedule.bms.BillingBillTask"/>

                   <beanid="cronTriggerBean7" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">

                             <propertyname="jobDetail" ref="jobDetail7"></property>

                             <propertyname="cronExpression" value="0/5 * * * * ?"></property>

                   </bean>

          參考 http://blog.csdn.net/lkforce/article/details/51841890

          posted @ 2018-03-12 19:58 風(fēng)人園 閱讀(388) | 評(píng)論 (0)編輯 收藏

          spring 3.0 async 異步方法 設(shè)置

          為了解決一些比較費(fèi)時(shí)且不是很緊要的任務(wù),將此任務(wù)轉(zhuǎn)為異步任務(wù)處理,提高前端操作體驗(yàn)。 spring 中 自帶注解 @Async. 配置如下 applicationContext.xml 中 增加 task的引用 如上配置之后,只需要在 需要進(jìn)行異步調(diào)用的方法前面增加 注解就可以了。 @Async public void updateOrderBillItemPQty(String deptId, String orderNo, Integer orderItemSid, Double pQty) { 注:需要注意,同一個(gè)對(duì)象里面方法調(diào)用,不會(huì)作為異步方法執(zhí)行。

          posted @ 2017-05-24 14:27 風(fēng)人園 閱讀(263) | 評(píng)論 (0)編輯 收藏

          android ResourceNotFoundException


          在對(duì) TextView 或者 EditText 進(jìn)行賦值時(shí),調(diào)用setText()方法,一定要注意,使用String類型,不要使用int 或者long,否則 會(huì)出現(xiàn)找不到資源的異常。系統(tǒng)自動(dòng)會(huì)將int作為一個(gè)資源ID,然后去R 里面找,結(jié)果找不到。

          posted @ 2016-12-21 20:48 風(fēng)人園 閱讀(137) | 評(píng)論 (0)編輯 收藏

          android 系統(tǒng)提示對(duì)話框(AlertDialog)的使用(zt)

               摘要: http://blog.csdn.net/meng425841867/article/details/8523730 在按鍵單擊事件中添加創(chuàng)建對(duì)話框并設(shè)置相關(guān)屬性。        [java] view plain copy dialogButton=(Button)findViewBy...  閱讀全文

          posted @ 2016-12-02 12:54 風(fēng)人園 閱讀(476) | 評(píng)論 (0)編輯 收藏

          Android 自定義ListView adapter(zt)

               摘要: http://daoshud1.iteye.com/blog/1874241 本文講實(shí)現(xiàn)一個(gè)自定義列表的Android程序,程序?qū)?shí)現(xiàn)一個(gè)使用自定義的適配器(Adapter)綁定 數(shù)據(jù),通過contextView.setTag綁定數(shù)據(jù)有按鈕的ListView。 系統(tǒng)顯示列表(ListView)時(shí),首先會(huì)實(shí)例化一個(gè)適配器,本文將實(shí)例化一個(gè)自定義的適配器。實(shí)現(xiàn) 自定義適...  閱讀全文

          posted @ 2016-12-01 13:13 風(fēng)人園 閱讀(168) | 評(píng)論 (0)編輯 收藏

          Android之SimpleAdapter簡單實(shí)例和SimpleAdapter參數(shù)說明(zt)

               摘要: http://blog.csdn.net/x605940745/article/details/11981049 SimpleAdapter的參數(shù)說明 第一個(gè)參數(shù) 表示訪問整個(gè)android應(yīng)用程序接口,基本上所有的組件都需要 第二個(gè)參數(shù)表示生成一個(gè)Map(String ,Object)列表選項(xiàng) 第三個(gè)參數(shù)表示界面布局的id  表示該文件作為列表項(xiàng)的組件&...  閱讀全文

          posted @ 2016-12-01 13:12 風(fēng)人園 閱讀(184) | 評(píng)論 (0)編輯 收藏

          android開發(fā)教程之listview使用方法

          首先是布局文件,這里需要兩個(gè)布局文件,一個(gè)是放置列表控件的Activity對(duì)應(yīng)的布局文件 main.xml,另一個(gè)是ListView中每一行信息顯示所對(duì)應(yīng)的布局 list_item.xml 這一步需要注意的問題是ListView 控件的id要使用Android系統(tǒng)內(nèi)置的 android:id="@android:id/list"

          main.xml
          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width
          ="match_parent"
              android:layout_height
          ="match_parent"
              android:orientation
          ="vertical" >
                  
          <ListView 
                  
          android:id="@android:id/list"
                  android:layout_width
          ="match_parent"
                  android:layout_height
          ="match_parent"
                  android:padding
          ="20dip"/>
          </LinearLayout>

          list_item.xml
          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width
          ="match_parent"
          android:layout_height
          ="match_parent"
          android:orientation
          ="horizontal" >

          <TextView
          android:id="@+id/user_name"
          android:layout_width
          ="match_parent"
          android:layout_height
          ="match_parent"
          android:layout_weight
          ="1"/>
          <TextView
          android:id="@+id/user_id"
          android:layout_width
          ="match_parent"
          android:layout_height
          ="match_parent"
          android:layout_weight
          ="1"/>
          </LinearLayout>


          然后就設(shè)置MainActivity中的代碼了:基本思想就是先將數(shù)據(jù)添加到ArrayList中,然后在設(shè)置SimpleAdapter適配器完成設(shè)置,入下:

          package com.example.android_newlistview;

          import java.util.ArrayList;
          import java.util.HashMap;
          import java.util.Map;

          import android.os.Bundle;
          import android.app.Activity;
          import android.app.ListActivity;
          import android.view.Menu;
          import android.widget.SimpleAdapter;

          public class MainActivity extends ListActivity {


          String[] from
          ={"name","id"}; //這里是ListView顯示內(nèi)容每一列的列名
          int[] to={R.id.user_name,R.id.user_id}; //這里是ListView顯示每一列對(duì)應(yīng)的list_item中控件的id

          String[] userName
          ={"zhangsan","lisi","wangwu","zhaoliu"}; //這里第一列所要顯示的人名
          String[] userId={"1001","1002","1003","1004"}; //這里是人名對(duì)應(yīng)的ID

          ArrayList
          <HashMap<String,String>> list=null;
          HashMap
          <String,String> map=null;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          //為MainActivity設(shè)置主布局
          //創(chuàng)建ArrayList對(duì)象;
          list=new ArrayList<HashMap<String,String>>();
          //將數(shù)據(jù)存放進(jìn)ArrayList對(duì)象中,數(shù)據(jù)安排的結(jié)構(gòu)是,ListView的一行數(shù)據(jù)對(duì)應(yīng)一個(gè)HashMap對(duì)象,
          //HashMap對(duì)象,以列名作為鍵,以該列的值作為Value,將各列信息添加進(jìn)map中,然后再把每一列對(duì)應(yīng)
          //的map對(duì)象添加到ArrayList中

          for(int i=0; i<4; i++){
          map
          =new HashMap<String,String>(); //為避免產(chǎn)生空指針異常,有幾列就創(chuàng)建幾個(gè)map對(duì)象
          map.put("id", userId[i]);
          map.put(
          "name", userName[i]);
          list.add(map);
          }


          //創(chuàng)建一個(gè)SimpleAdapter對(duì)象
          SimpleAdapter adapter=new SimpleAdapter(this,list,R.layout.list_item,from,to);
          //調(diào)用ListActivity的setListAdapter方法,為ListView設(shè)置適配器
          setListAdapter(adapter);
          }

          }


          另外對(duì)點(diǎn)擊某一行作出響應(yīng)的方法是覆寫onListItemClick方法,根據(jù)返回的position(從0開始):
          @Override
          protected void onListItemClick(ListView l, View v, int position, long id) {
          // TODO Auto-generated method stub
          super.onListItemClick(l, v, position, id);
          }


          posted @ 2016-12-01 13:08 風(fēng)人園 閱讀(157) | 評(píng)論 (0)編輯 收藏

          android json 數(shù)據(jù)解析



          單數(shù)據(jù){'singer':{'id':01,'name':'tom','gender':'男'}} 
          多個(gè)數(shù)據(jù){"singers":[ 
                  {'id':02,'name':'tom','gender':'男'}, 
                   {'id':03,'name':'jerry,'gender':'男'}, 
          {'id':04,'name':'jim,'gender':'男'}, 
          {'id':05,'name':'lily,'gender':'女'}]}          
          // 普通Json數(shù)據(jù)解析 
              private void parseJson(String strResult) 
                  
          try 
                      JSONObject jsonObj 
          = new JSONObject(strResult).getJSONObject("singer"); 
                      
          int id = jsonObj.getInt("id"); 
                      String name 
          = jsonObj.getString("name"); 
                      String gender 
          = jsonObj.getString("gender"); 
                      tvJson.setText(
          "ID號(hào)"+id + ", 姓名:" + name + ",性別:" + gender); 
                  }
           catch (JSONException e) 
                      System.out.println(
          "Json parse error"); 
                      e.printStackTrace(); 
                  }
           
              }
           
              
          //解析多個(gè)數(shù)據(jù)的Json
             private void parseJsonMulti(String strResult) 
                 
          try 
                      JSONArray jsonObjs 
          = new JSONObject(strResult).getJSONArray("singers"); 
                      String s 
          = ""
                      
          for(int i = 0; i < jsonObjs.length() ; i++)
                          JSONObject jsonObj 
          = ((JSONObject)jsonObjs.opt(i)).getJSONObject("singer"); 
                          
          int id = jsonObj.getInt("id"); 
                          String name 
          = jsonObj.getString("name"); 
                          String gender 
          = jsonObj.getString("gender"); 
                          s 
          +=  "ID號(hào)"+id + ", 姓名:" + name + ",性別:" + gender+ "\n" ; 
                      }
           
                      tvJson.setText(s); 
                  }
           catch (JSONException e) 
                      System.out.println(
          "Jsons parse error !"); 
                      e.printStackTrace(); 
                  }
           
              }
           

          posted @ 2016-11-29 15:09 風(fēng)人園 閱讀(163) | 評(píng)論 (0)編輯 收藏

          button onClick 事件的幾種調(diào)用方式



          1. //第一種方式    
          2.         Button Btn1 = (Button)findViewById(R.id.button1);//獲取按鈕資源    
          3.         Btn1.setOnClickListener(new Button.OnClickListener(){//創(chuàng)建監(jiān)聽    
          4.             public void onClick(View v) {    
          5.                 String strTmp = "點(diǎn)擊Button01";    
          6.                 Ev1.setText(strTmp);    
          7.             }    
          8.   
          9.         });   

          1.     //第二種方式(Android1.6版本及以后的版本中提供了,直接在layout中設(shè)置)    
          2.     public void Btn3OnClick(View view){    
          3.         String strTmp="點(diǎn)擊Button03";  
          4.         Ev1.setText(strTmp);  
          5.   
          6.     }  

          1.  <Button  
          2.         android:id="@+id/button3"  
          3.         android:layout_width="wrap_content"  
          4.         android:layout_height="wrap_content"  
          5.         android:text="Button3"   
          6.         android:onClick="Btn3OnClick"/>  


          第三種方式 activity 實(shí)現(xiàn) 單擊監(jiān)聽接口

          public class TestButtonActivity extends Activity implements OnClickListener {
          Button btn1, btn2;
          Toast tst;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_test_button);
          btn1 = (Button) findViewById(R.id.button1);
          btn2 = (Button) findViewById(R.id.button2);
          btn1.setOnClickListener(this);
          btn2.setOnClickListener(this);
          }
          @Override
          public void onClick(View v) {
          // TODO Auto-generated method stub
          switch (v.getId()) {
          case R.id.button1:
          tst = Toast.makeText(this, "111111111", Toast.LENGTH_SHORT);
          tst.show();
          break;
          case R.id.button2:
          tst = Toast.makeText(this, "222222222", Toast.LENGTH_SHORT);
          tst.show();
          break;
          default:
          break;
          }
          }
          }




           

          posted @ 2016-11-29 13:31 風(fēng)人園 閱讀(906) | 評(píng)論 (0)編輯 收藏

          打開activity的幾種方式


          一、直接打開,不傳遞參數(shù)
          Intent intent = new Intent(this, Activity.class);
          startActivity(intent);


          二、傳遞參數(shù)
          public void OpenNew(View v) {
              
          //新建一個(gè)顯式意圖,第一個(gè)參數(shù)為當(dāng)前Activity類對(duì)象,第二個(gè)參數(shù)為你要打開的Activity類
              Intent intent =new Intent(MainActivity.this,MainActivity2.class);
              
              
          //用Bundle攜帶數(shù)據(jù)
              Bundle bundle=new Bundle();
              
          //傳遞name參數(shù)為tinyphp
              bundle.putString("name""tinyphp");
              intent.putExtras(bundle);
              
              startActivity(intent);       
           //1.要關(guān)閉的頁面  
              protected void onCreate(Bundle savedInstanceState) {  
                  
          super.onCreate(savedInstanceState);  
                  setContentView(R.layout.otheractivity);  
                  Intent intent 
          = this.getIntent();  
                  intent.putExtra(
          "tel"12345);  
                  
          //設(shè)置requestCode和帶有數(shù)據(jù)的intent對(duì)象  
                  OtherActivity.this.setResult(3, intent);  
                  
          //馬上關(guān)閉Activity  
                  this.finish();  
              }
            
                
              
          //2.上面的頁面關(guān)閉時(shí),此頁面進(jìn)行數(shù)據(jù)的接收  
              class ButtonListener implements android.view.View.OnClickListener{  
                  @Override  
                  
          public void onClick(View arg0) {  
                      Intent intent 
          = new Intent();  
                      intent.setClass(MainActivity.
          this, OtherActivity.class);  
                      
          //與普通的start方法不同,需要設(shè)置requestCode  
                      startActivityForResult(intent, 1);  
                  }
            
              }
            
                
              
          //如果要進(jìn)行此操作,需要在數(shù)據(jù)接收頁面中復(fù)寫activity的onActivityResul()方法  
              @Override  
              
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
                  
          super.onActivityResult(requestCode, resultCode, data);  
                  
          int tel = 0;  
                  
          //根據(jù)返回碼resultCode來判斷下一步進(jìn)行的業(yè)務(wù)代碼  
                  if(resultCode==3){  
                      tel 
          = data.getIntExtra("tel"0);  
                  }
            
                  Log.i(TAG, 
          "tel--------->"+String.valueOf(tel));  
              }
            
           
              }



          三、回傳參數(shù)


          posted @ 2016-11-29 13:24 風(fēng)人園 閱讀(444) | 評(píng)論 (0)編輯 收藏

          spring mvc @ExceptionHandler 異常處理

          spring mvc 統(tǒng)一的異常處理,有兩種方式。
          一、exceptionResolver
          二、ExceptionHandler

          兩者不能同時(shí)配置。如果配置了第一種,則第二種無效。就因?yàn)檫@個(gè)原因,找了一天的問題。

          ExceptionHandler 通過注解的方式,進(jìn)行配置,只需要在某個(gè)controller 中設(shè)置了這個(gè)注解,則這個(gè)controller中的所有異常都會(huì)通過這個(gè)方法進(jìn)行處理。

          比如rest controller,增加一個(gè)
              @ExceptionHandler
              
          public String exp(HttpServletRequest request, Exception ex) {  
                  
                  Map map 
          = new HashMap();
                  
                  logger.error(
          "error," + UUID.randomUUID().toString(), ex);
                  request.setAttribute(
          "ex", ex);  
                  
                  String msg 
          = ex.getMessage();
                  
                  map.put(
          "success""0"); 
                  map.put(
          "msg", msg);
                  
                  String rtnjson 
          = JSONUtil.objectToJson(map);
                  
                  request.setAttribute(
          "json", rtnjson);
                  
                  
          return "json";
              }
           

          這樣,這個(gè)controler中的異常,都會(huì)由這個(gè)異常處理方法,進(jìn)行統(tǒng)一處理,生成異常json。避免在各個(gè)方法中通過try catch 的方法,進(jìn)行異常處理。

          posted @ 2016-11-08 08:32 風(fēng)人園 閱讀(394) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 晴隆县| 旬阳县| 政和县| 黑河市| 女性| 清河县| 吉水县| 长泰县| 乌海市| 城市| 巴马| 武宣县| 庆云县| 黔西| 明溪县| 阜城县| 大冶市| 南和县| 孝感市| 法库县| 丹巴县| 古交市| 铁岭市| 夏津县| 祁阳县| 潮安县| 合阳县| 秦安县| 铁力市| 周宁县| 上高县| 祁门县| 米易县| 马龙县| 威远县| 漠河县| 离岛区| 屯昌县| 洪江市| 壶关县| 武定县|