【開源】 bsf.mvc spingboot的擴充,bsf.mvcspingboot

來源:互聯網
上載者:User

【開源】 bsf.mvc spingboot的擴充,bsf.mvcspingboot

springboot的擴充實現,讓springboot開發更加簡單;形成demo模板,以後開發更方便。

開源地址:https://gitee.com/chejiangyi/bsf.mvc/tree/master/

1. 自動requestmapping(無需配置)實現。
2. freemarker java擴充實現,使freemarker更加便於使用。
3. request 參數大小寫相容實現,傳入參數不再區分大小寫。
date日期參數相容,支援對象綁定對public欄位的自動對應。
4. url 大小寫相容,不敏感。
5. 提供預設分頁控制項。
6. 支援.net mvc的寫法。

1. 自動requestmapping(無需配置)實現。
 1 /** 2  * sprinboot擴充實現,自動requestmapping(public,傳回值為ModelAndView類型/或子類)的方法 3  */ 4 public class SpringMvcDemoController extends SpringMvcController { 5     public ModelAndView index(Integer a,String b) 6     { 7         return this.pageVisit(m->{ 8             //分頁控制項實現說明 9             new Pager1(1,20).setPageSize(10).out();10         });11     }12 13 14     public ModelAndView index2()15     {16         return new ModelAndView();17     }18 }
application.properties 檔案中配置,加快自動對應啟動速度。
#bsf.mvc自動requestmapping注入的包路徑,逗號分割多個
bsf.mvcpackage=com.bsf.mvc.webdemo.controller

2. freemarker java擴充實現,使freemarker更加便於使用。
freemarker頁面
${Html.s("pagetitle","編輯分類")}${Html.g("pagetitle")}${Html.p(model.createtime)}${Html.w(c.selected,"selected='selected'","")}

 後台代碼

/** * TemplateProvider 縮寫簡寫擴充,方便頁面模板裡面使用可以被繼承,不斷擴充 */public class SimpleTemplateProvider extends TemplateProvider {    /**     * getattr方法 縮寫     */    public Object g(String key) {        return getattr(key);    }    /**     * setattr方法 縮寫     */    public void s(String key, Object value) {        setattr(key, value);    }    /**     * where 簡寫     */    public Object w(boolean istrue, Object trueObj, Object falseObj) {        return where(istrue, trueObj, falseObj);    }    /**     * print 縮寫     */    public String p(Object o) {        return print(o);    }}

 5. 提供預設分頁控制項。

freemaker

<#macro _pager formid="searchForm">    ${pagehtml!}    <script type="text/javascript">
  //js分頁回調 function pagerfunction(pageindex) { $("#${formid}").prepend("<input type='hidden' name='pageindex' value='"+pageindex+"'/>"); $("#${formid}").prepend("<input type='hidden' name='pagesize' value='"+'${pagesize!}'+"'/>"); $("#${formid}").submit(); } </script></#macro>

 後台代碼

new Pager1(pageindex,count).setPageSize(10).out();

6. 支援.net mvc的寫法。

/** * 擴充springboot 類比.net mvc的寫法 * 需要繼承 NetController */public class NetMvcDemoController extends NetMvcController {    public ActionResult index(Integer a,String b)    {        //分頁控制項實現說明        new Pager1(1,20).setPageSize(10).out();        return view();    }    public ActionResult index2()    {        List a = new ArrayList<String>();        return view("/netmvcdemo/index2",a);    }    public ActionResult json()    {        List a = new ArrayList<String>();        return json(a);    }}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.