#
摘要: 父页面bootstrap模态框: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" > <div class="modal-dialog modal-lg"> ...
阅读全文
来源:
https://blog.csdn.net/xu1916659422/article/details/77971867
mysql新增语句
insert into 表名(字段,字段。。。) values ( 值,值 。。。);此种适合单条插入。
批量插入,
一种可以在代码中循环着执行上面的语句,但是这种效率太差,下面会有对比,看看它有多差。
另一种,可以用mysql支持的批量插入语句,
insert into
表名(字段,字段。。。) values ( 值,值 。。。),( 值,值 。。。),( 值,值 。。。)....
这种方式相比起来,更高效。
实现过程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才不会获取为空
跟自增主键相比就这点区别,当然了这里的获取主键id的方式为 select uuid()
当然也可以另写别生成函数。-->
<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循环集合用的
collection="list" 接收的map集合中的key 用以循环key对应的属性
separator="," 表示每次循环完毕,在sql后面放一个逗号
item="cus" 每次循环的实体对象 名称随意-->
<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 + '\'' +
'}';
}
}
接口
int add(Customer customer);
int batchInsert(Map
<String,Object> param);
实现
实现
/**
* 新增数据
* @param customer
* @return
*/
public int add(Customer customer) {
return insert("customer.insert", customer);
}
/**
* 批量插入数据
* @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;
}
POM中引入
<!--JSON树形结构 转换-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
实体类创建
import net.sf.json.JSONArray;
import java.util.ArrayList;
import java.util.List;
/**
* 构造目录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;
}
// 构建JSON树形结构
public String buildJSONTree() {
List<Node> nodeTree = buildTree();
JSONArray jsonArray = JSONArray.fromObject(nodeTree);
return jsonArray.toString();
}
// 构建树形结构
public List<Node> buildTree() {
List<Node> treeNodes = new ArrayList<>();
List<Node> rootNodes = getRootNodes();
for (Node rootNode : rootNodes) {
buildChildNodes(rootNode);
treeNodes.add(rootNode);
}
return treeNodes;
}
// 递归子节点
public void buildChildNodes(Node node) {
List<Node> children = getChildNodes(node);
if (!children.isEmpty()) {
for (Node child : children) {
buildChildNodes(child);
}
node.setChildren(children);
}
}
// 获取父节点下所有的子节点
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;
}
// 判断是否为根节点
public boolean rootNode(Node node) {
boolean isRootNode = true;
for (Node n : nodes) {
if (node.getPid().equals(n.getId())) {
isRootNode = false;
break;
}
}
return isRootNode;
}
// 获取集合中所有的根节点
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
<!--根据条件查询返回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:返回结果
//树形结构
@RequestMapping("left")
ModelAndView left() throws JSONException {
String mavStr = "";
BsItemtype queryItemtype = new BsItemtype();
//查询根目录树
// queryItemtype.setUpcode("00");
// 获取全部目录节点
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>
前台:
<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}" />
<a 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>
//分页跳转方法
function page(pageNum) {
$("#start").val(pageNum);
$("#queryform").submit();
}
此种方法可以将搜索查询框内容通过form表单的方式提交给controller,controller再分页,但点“下一页”事件多点二次很容易导致浏览器假死。
第二种方式:直接通过href传值,这种方式不死机。
<div class="pagelist">
<a th:href="@{/bbs/list(start=0,title=${queryBbs.title})}">[首 页]</a>
<a th:href="@{/bbs/list(start=${page.pageNum-1},title=${queryBbs.title})}">[上一页]</a>
<a th:href="@{/bbs/list(start=${page.pageNum+1},title=${queryBbs.title})}">[下一页]</a>
<a th:href="@{/bbs/list(start=${page.pages},title=${queryBbs.title})}">[尾 页]</a>
共[[${page.total}]]条记录
</div>
摘要: 错误如下:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->org.thymeleaf.exceptions.TemplateInputException: An error happened during&nbs...
阅读全文
windows风格
https://www.toufu.xyz
layui
网页模板素材
http://www.htmlsucai.com/forum-78-1.html
http://www.cssmoban.com/cssthemes/houtaimoban/
http://www.16sucai.com/
https://www.58pic.com/
Spring+Mybatis框架整合时,根据条件查询数据,发生异常
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);
解决方法:在参数前加@Param标签
public List<Userinfo> findAll(@Param("sname") String sname);
$("input[name='a']").each(function () {
Aval = $(this).val();
alert(Aval);
});
解释:取当前页面所有name='a'的input元素,循环每一个取到的元素,将其value的值赋
给Aval,并输出。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
或
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
如果mysql只能本地连接,不能远程 连接
第一步: update user set host='%' where user='root';
第二步:重启服务