JBOSS 點滴

          豐豐的博客

          #

          Bootstrap 模態(tài)框 + iframe > 打開子頁面 > 數(shù)據(jù)傳輸/關(guān)閉模態(tài)框

               摘要: 父頁面bootstrap模態(tài)框: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" > <div class="modal-dialog modal-lg"> ...  閱讀全文

          posted @ 2019-05-28 21:23 半導(dǎo)體 閱讀(330) | 評論 (0)編輯 收藏

          mybatis學(xué)習(xí)之路----mysql批量新增數(shù)據(jù)

          來源:
          https://blog.csdn.net/xu1916659422/article/details/77971867
           
             mysql新增語句 
              insert into 表名(字段,字段。。。) values ( 值,值 。。。);此種適合單條插入。
          批量插入,
             一種可以在代碼中循環(huán)著執(zhí)行上面的語句,但是這種效率太差,下面會有對比,看看它有多差。
          另一種,可以用mysql支持的批量插入語句,
          insert into
               表名(字段,字段。。。) values ( 值,值 。。。),( 值,值 。。。),( 值,值 。。。)....
          這種方式相比起來,更高效。
          實現(xiàn)過程mapper.xml
           

              <!-- 跟普通的insert沒有什么不同的地方 ,主要用來跟下面的批量插入做對比。-->
              <insert id="insert" parameterType="com.soft.mybatis.model.Customer">
                  <!-- 跟自增主鍵方式相比,這里的不同之處只有兩點
                              1  insert語句需要寫id字段了,并且 values里面也不能省略
                              2 selectKey 的order屬性需要寫成BEFORE 因為這樣才能將生成的uuid主鍵放入到model中,
                              這樣后面的insert的values里面的id才不會獲取為空
                        跟自增主鍵相比就這點區(qū)別,當(dāng)然了這里的獲取主鍵id的方式為 select uuid()
                        當(dāng)然也可以另寫別生成函數(shù)。-->
                  <selectKey keyProperty="id" order="BEFORE" resultType="String">
                      select uuid()
                  </selectKey>
                  insert into t_customer (id,c_name,c_sex,c_ceroNo,c_ceroType,c_age)
                  values (#{id},#{name},#{sex},#{ceroNo},#{ceroType},#{age})
              </insert>
           
              <!-- 批量插入, -->
              <insert id="batchInsert" parameterType="java.util.Map">
                  <!-- 這里只做演示用,真正項目中不會寫的這么簡單。 -->
                  insert into
                    t_customer (id,c_name,c_sex,c_ceroNo,c_ceroType,c_age)
                  values
                  <!-- foreach mybatis循環(huán)集合用的
                        collection="list" 接收的map集合中的key 用以循環(huán)key對應(yīng)的屬性
                           separator=","  表示每次循環(huán)完畢,在sql后面放一個逗號
                           item="cus" 每次循環(huán)的實體對象 名稱隨意-->
                  <foreach collection="list" separator="," item="cus">
                      <!-- 組裝values對象,因為這張表的主鍵為非自增主鍵,所以這里 (select uuid()) 用于生成id的值-->
                      ((select uuid()),#{cus.name},#{cus.sex},#{cus.ceroNo},#{cus.ceroType},#{cus.age})
                  </foreach>
              </insert>
          實體model對象

          package com.soft.mybatis.model;

           

          /**

           * Created by xuweiwei on 2017/9/10.

           */

          public class Customer {

           

              private String id;

              private String name;

              private Integer age;

              private Integer sex;

              private String ceroNo;

              private Integer ceroType;

           

              public String getId() {

                  return id;

              }

           

              public void setId(String id) {

                  this.id = id;

              }

           

              public String getName() {

                  return name;

              }

           

              public void setName(String name) {

                  this.name = name;

              }

           

              public Integer getAge() {

                  return age;

              }

           

              public void setAge(Integer age) {

                  this.age = age;

              }

           

              public Integer getSex() {

                  return sex;

              }

           

              public void setSex(Integer sex) {

                  this.sex = sex;

              }

           

              public String getCeroNo() {

                  return ceroNo;

              }

           

              public void setCeroNo(String ceroNo) {

                  this.ceroNo = ceroNo;

              }

           

              public Integer getCeroType() {

                  return ceroType;

              }

           

              public void setCeroType(Integer ceroType) {

                  this.ceroType = ceroType;

              }

           

              @Override

              public String toString() {

                  return "Customer{" +

                          "id='" + id + '\'' +

                          ", name='" + name + '\'' +

                          ", age=" + age +

                          ", sex=" + sex +

                          ", ceroNo='" + ceroNo + '\'' +

                          ", ceroType='" + ceroType + '\'' +

                          '}';

              }

          }
          接口
          1. int add(Customer customer);
          2.     int batchInsert(Map<String,Object> param);

            實現(xiàn)
          實現(xiàn)

             
          /**

               * 新增數(shù)據(jù)

               * 
          @param customer

               * 
          @return

               
          */

              
          public int add(Customer customer) {

                  
          return insert("customer.insert", customer);

              }

           

              
          /**

               * 批量插入數(shù)據(jù)

               * 
          @param param

               * 
          @return

               
          */

              
          public int batchInsert(Map<String,Object> param) {

                  
          return insert("customer.batchInsert", param);

              }

           

              
          /**

               * 公共部分

               * 
          @param statementId

               * 
          @param obj

               * 
          @return

               
          */

              
          private int insert(String statementId, Object obj){

                  SqlSession sqlSession 
          = null;

                  
          try {

                      sqlSession 
          = SqlsessionUtil.getSqlSession();

                      
          int key =  sqlSession.insert(statementId, obj);

                      
          // commit

                      sqlSession.commit();

                      
          return key;

                  } 
          catch (Exception e) {

                      sqlSession.rollback();

                      e.printStackTrace();

                  } 
          finally {

                      SqlsessionUtil.closeSession(sqlSession);

                  }

                  
          return 0;

              }

          posted @ 2019-05-23 11:29 半導(dǎo)體 閱讀(137) | 評論 (0)編輯 收藏

          springboot中樹形結(jié)構(gòu)的開發(fā)

          POM中引入
                  <!--JSON樹形結(jié)構(gòu) 轉(zhuǎn)換-->
                  
          <dependency>
                      
          <groupId>net.sf.json-lib</groupId>
                      
          <artifactId>json-lib</artifactId>
                      
          <version>2.4</version>
                      
          <classifier>jdk15</classifier>
                  
          </dependency>
          實體類創(chuàng)建
          import net.sf.json.JSONArray;

          import java.util.ArrayList;
          import java.util.List;

          /**
           * 構(gòu)造目錄JSON樹
           * Created by   network on 2019/5/22
           
          */
          public class TreeBuilder {

              List
          <Node> nodes = new ArrayList<>();

              
          public String buildTree(List<Node> nodes) {

                  TreeBuilder treeBuilder 
          = new TreeBuilder(nodes);

                  
          return treeBuilder.buildJSONTree();
              }

              
          public TreeBuilder() {
              }

              
          public TreeBuilder(List<Node> nodes) {
                  
          super();
                  
          this.nodes = nodes;
              }

              
          // 構(gòu)建JSON樹形結(jié)構(gòu)
              public String buildJSONTree() {
                  List
          <Node> nodeTree = buildTree();
                  JSONArray jsonArray 
          = JSONArray.fromObject(nodeTree);
                  
          return jsonArray.toString();
              }

              
          // 構(gòu)建樹形結(jié)構(gòu)
              public List<Node> buildTree() {
                  List
          <Node> treeNodes = new ArrayList<>();
                  List
          <Node> rootNodes = getRootNodes();
                  
          for (Node rootNode : rootNodes) {
                      buildChildNodes(rootNode);
                      treeNodes.add(rootNode);
                  }
                  
          return treeNodes;
              }

              
          // 遞歸子節(jié)點
              public void buildChildNodes(Node node) {
                  List
          <Node> children = getChildNodes(node);
                  
          if (!children.isEmpty()) {
                      
          for (Node child : children) {
                          buildChildNodes(child);
                      }
                      node.setChildren(children);
                  }
              }

              
          // 獲取父節(jié)點下所有的子節(jié)點
              public List<Node> getChildNodes(Node pnode) {
                  List
          <Node> childNodes = new ArrayList<>();
                  
          for (Node n : nodes) {
                      
          if (pnode.getId().equals(n.getPid())) {
                          childNodes.add(n);
                      }
                  }
                  
          return childNodes;
              }

              
          // 判斷是否為根節(jié)點
              public boolean rootNode(Node node) {
                  
          boolean isRootNode = true;
                  
          for (Node n : nodes) {
                      
          if (node.getPid().equals(n.getId())) {
                          isRootNode 
          = false;
                          
          break;
                      }
                  }
                  
          return isRootNode;
              }

              
          // 獲取集合中所有的根節(jié)點
              public List<Node> getRootNodes() {
                  List
          <Node> rootNodes = new ArrayList<>();
                  
          for (Node n : nodes) {
                      
          if (rootNode(n)) {
                          rootNodes.add(n);
                      }
                  }
                  
          return rootNodes;
              }

              
          public static class Node {

                  
          private String id;
                  
          private String pid;
                  
          private String name;
                  
          private List<Node> children;

                  
          public Node() {
                  }

                  
          public Node(String id, String pid, String name) {
                      
          super();
                      
          this.id = id;
                      
          this.pid = pid;
                      
          this.name = name;
                  }

                  
          public String getId() {
                      
          return id;
                  }

                  
          public void setId(String id) {
                      
          this.id = id;
                  }

                  
          public String getPid() {
                      
          return pid;
                  }

                  
          public void setPid(String pid) {
                      
          this.pid = pid;
                  }

                  
          public String getName() {
                      
          return name;
                  }

                  
          public void setName(String name) {
                      
          this.name = name;
                  }


                  
          public List<Node> getChildren() {
                      
          return children;
                  }

                  
          public void setChildren(List<Node> children) {
                      
          this.children = children;
                  }
              }
          }
          mapper.xml
              <!--根據(jù)條件查詢返回Node-->
              
          <select id="findByItemtypeTree" parameterType="BsItemtype" resultType="Node">
                  SELECT upcode as pid,itemname as name,itemtypecode as id FROM 表名 WHERE 1=1
                  
          <if test="upcode != null  and upcode != '' ">
                      and upcode = #{值}
                  
          </if>
              
          </select>
          controller:返回結(jié)果
              //樹形結(jié)構(gòu)
              @RequestMapping("left")
              ModelAndView left() 
          throws JSONException {
                  String mavStr 
          = "";
                  BsItemtype queryItemtype 
          = new BsItemtype();
                  
          //查詢根目錄樹
                
          //  queryItemtype.setUpcode("00");
                  
          // 獲取全部目錄節(jié)點
                  List<TreeBuilder.Node> itemtypeTree = itemtypeService.findByItemtypeTree();

                  
          // 拼裝樹形json字符串
                   mavStr = new TreeBuilder().buildTree(itemtypeTree);
                  mavStr 
          = mavStr.replaceAll("\"children\"","\"nodes\"");
                  mavStr
          = mavStr.replaceAll("\"id\"","\"value\"");
                  mavStr 
          = mavStr.replaceAll("\"name\"","\"text\"");
                  ModelAndView mav 
          = new ModelAndView("/bs/itemtype/itemtypeLeft.html");//配置返回路徑
                  System.out.println(mavStr);
                  mav.addObject(
          "mavStr", mavStr.toString());
                  
          return mav;
              }
          DAO層:
          List<TreeBuilder.Node> findByItemtypeTree();

          html
          <!DOCTYPE html>
          <html xmlns:th="http://www.thymeleaf.org">
          <html lang="en">
          <head>
              
          <meta charset="UTF-8">
              
          <title></title>

              
          <!-- Required Stylesheets -->
              
          <link href="/oastyle/css/bootstrap.css" rel="stylesheet">
              
          <!-- Required Javascript -->
              
          <script src="/js/jquery.js"></script>
              
          <script src="/js//bootstrap-treeview.js"></script>
          </head>
          <body>
          <div id="tree"></div>
          <script th:inline="javascript">
          var tree = eval([[${mavStr}]]);
                   
          function getTree() {
                  
          // Some logic to retrieve, or generate tree structure
                  return tree;
              }

              $('#tree').treeview({
                  data: getTree(),
                  enableLinks: 
          true});

              $('#tree').on('nodeSelected',
          function(event, data) {
                    window.parent.itemtypeRight.location.href
          ="/itemtype/list?upcode="+data.value;
              });

          </script>

          </body>
          </html>

          posted @ 2019-05-21 19:08 半導(dǎo)體 閱讀(2072) | 評論 (0)編輯 收藏

          技巧

          layui
          可以做表格排序。

          posted @ 2019-05-16 21:14 半導(dǎo)體 閱讀(82) | 評論 (0)編輯 收藏

          分頁方式:

          前臺:
          <form   method="post" action = "/bbs/list"  id="queryform">
                  
          <input type="hidden" name="start" id="start"/>
                  
          <li>搜索:</li>
                          
          <input type="text" placeholder="請輸入公告名稱" name="title"  th:value ="${queryBbs.title}" />
                        
          <href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a>
              
          </form>
              //搜索
              function changesearch() {
                  $(
          "#queryform").submit();
              }
          通過page傳值
          <div class="pagelist" th:include="common/footer::page"/>
          包含頁面
          <!--fotter-->
          <div class="pagelist" th:fragment="page">
              
          <a th:onclick="javascript:page(0)">[首 頁]</a>
              
          <a th:onclick="javascript:page([[${page.pageNum}]]-1)">[上一頁]</a>
              
          <a th:onclick="javascript:page([[${page.pageNum}]]+1)">[下一頁]</a>
              
          <a th:onclick="javascript:page([[${page.pages}]])">[尾 頁]</a>
              共[[${page.total}]]條記錄
          </div>
          //分頁跳轉(zhuǎn)方法
          function page(pageNum) {
          $(
          "#start").val(pageNum);
          $(
          "#queryform").submit();
          }
          此種方法可以將搜索查詢框內(nèi)容通過form表單的方式提交給controller,controller再分頁,但點“下一頁”事件多點二次很容易導(dǎo)致瀏覽器假死。

          第二種方式:直接通過href傳值,這種方式不死機(jī)。
                                  <div class="pagelist">
                                  
          <th:href="@{/bbs/list(start=0,title=${queryBbs.title})}">[首  頁]</a>
                                  
          <th:href="@{/bbs/list(start=${page.pageNum-1},title=${queryBbs.title})}">[上一頁]</a>
                                  
          <th:href="@{/bbs/list(start=${page.pageNum+1},title=${queryBbs.title})}">[下一頁]</a>
                                  
          <th:href="@{/bbs/list(start=${page.pages},title=${queryBbs.title})}">[尾  頁]</a>
                                      共[[${page.total}]]條記錄
                                  
          </div>

          posted @ 2019-05-15 15:21 半導(dǎo)體 閱讀(122) | 評論 (0)編輯 收藏

          org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing

               摘要: 錯誤如下:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->org.thymeleaf.exceptions.TemplateInputException: An error happened during&nbs...  閱讀全文

          posted @ 2019-05-12 15:15 半導(dǎo)體 閱讀(7839) | 評論 (0)編輯 收藏

          好看的界面

          windows風(fēng)格
          https://www.toufu.xyz
          layui

          網(wǎng)頁模板素材
          http://www.htmlsucai.com/forum-78-1.html
          http://www.cssmoban.com/cssthemes/houtaimoban/
          http://www.16sucai.com/
          https://www.58pic.com/

          posted @ 2019-05-11 23:17 半導(dǎo)體 閱讀(102) | 評論 (0)編輯 收藏

          Spring+Mybatis 查詢所有數(shù)據(jù)時發(fā)生異常:org.apache.ibatis.reflection.ReflectionException: There is no getter for

          Spring+Mybatis框架整合時,根據(jù)條件查詢數(shù)據(jù),發(fā)生異常
          Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'sname' in 'class java.lang.String'
          userinfoMapper.xml文件:
          <select id="findAll" parameterType="string" resultMap="userinfoMap">  select * from userinfo where sname like '%${sname}%' </select>
          UserinfoMapper接口:

          public List<Userinfo> findAll(String sname);
          解決方法:在參數(shù)前加@Param標(biāo)簽
          public List<Userinfo> findAll(@Param("sname") String sname);

          posted @ 2019-05-11 16:05 半導(dǎo)體 閱讀(1605) | 評論 (0)編輯 收藏

          全選輸出checkbox的值

          $("input[name='a']").each(function () {
                      Aval 
          = $(this).val();
                      alert(Aval);
                  });

          解釋:取當(dāng)前頁面所有name='a'的input元素,循環(huán)每一個取到的元素,將其value的值賦

          給Aval,并輸出。


          posted @ 2019-05-11 14:48 半導(dǎo)體 閱讀(100) | 評論 (0)編輯 收藏

          mysql8.0使用sqlyog無法連接時

           ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

           ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

          如果mysql只能本地連接,不能遠(yuǎn)程 連接
          第一步:
           update user set host='%' where user='root';
          第二步:重啟服務(wù)

          posted @ 2019-05-06 10:14 半導(dǎo)體 閱讀(259) | 評論 (0)編輯 收藏

          僅列出標(biāo)題
          共27頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 江达县| 城固县| 安溪县| 潮州市| 芦山县| 台前县| 桐梓县| 朔州市| 高州市| 兴安盟| 南昌县| 松潘县| 乐昌市| 株洲市| 浮梁县| 正镶白旗| 六安市| 涟水县| 贵德县| 乌鲁木齐市| 六盘水市| 许昌县| 新乐市| 安龙县| 芦溪县| 朔州市| 庆云县| 苏尼特左旗| 抚顺县| 正安县| 长阳| 韶关市| 镇坪县| 司法| 蛟河市| 六安市| 肥东县| 合肥市| 全椒县| 连江县| 凌源市|