springboot 笔记


一、springboot
第一步,用spring boot把程序启起来。第二启,服务对外提供restful服务,第三步,做两个服务,一个为注册服务器,另外一个向注册服务器进行注册

sprinboot静态资源访问,默认路径:

thymeleaf模板

 

1、前后端流程打通:

https://blog.csdn.net/xpf_user/article/details/78557782

 

CREATE TABLE `product` (

`id` int(11) NOT NULL UNIQUE AUTO_INCREMENT,
`count` int(11),
`name` char(30) NOT NULL, 

`price` char(30) NOT NULL, 

PRIMARY KEY (`id`) 

) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

 

INSERT INTO product (name, count, price) VALUES ( '葡萄', 1200, '4.5');
INSERT INTO product ( name, count, price) VALUES ( '柠檬', 300, '3.4');
INSERT INTO product ( name, count, price) VALUES ( '橙子', 200, '17.4');
INSERT INTO product ( name, count, price) VALUES ( '哈密瓜', 20, '16');

 

CREATE TABLE `student` (

 

`id` int(11) NOT NULL UNIQUE AUTO_INCREMENT, 

`name` char(30) NOT NULL,
`age` int(11),
`nation` char(30),
PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

INSERT INTO student (name, age, nation) VALUES ( 'Jack', 12, 'USA');
INSERT INTO student (name, age, nation) VALUES ( '小明', 13, 'China');
INSERT INTO student (name, age, nation) VALUES ( 'kettu', 12, 'UK');

 

2、RestFul 格式

https://www.cnblogs.com/xuwujing/p/8260935.html

3、增删改查

https://blog.csdn.net/zz2713634772/article/details/79542518

++https://blog.csdn.net/qazwsxpcm/article/details/79028689

 4、增删改查实现之更新

关于更新数据的流程
1)获取id值
function updateItem(idg){
var id = idg.replace(/\"/g, ""); // 去除双引号

$.ajax({
type: "get",
url: '/pro/updateview/'+ id,
dataType: "html",
contentType : "application/json",
async: false,
success: function(result) {
var newWin = window.open('', '_blank');
newWin.document.write(result);
},
error:function () {
//alert("更新失败! " )
}
});
}

2)后端处理
@RequestMapping(value = "pro/updateview/{id}",method = RequestMethod.GET)
@ResponseBody
public ModelAndView getUpdatePage(@PathVariable int id){
Product product = productService.queryById(id);

ModelAndView mav = new ModelAndView("/goods_update");
mav.addObject("product",product);

return mav;
}

3)前端页面渲染 (注意:使用thyleaf模板处理)
<tbody>
<tr>
<td>编号</td>
<td>
<input type="text" style="width: 200px; margin: 0px auto" th:value="${product.id}" contenteditable="false" id="itemId" disabled="true" placeholder="输入商品名称" >
</td>
</tr>
<tr>
<td>名称</td>
<td><input type="text" style="width: 200px; margin: 0px auto" th:value="${product.name}" id="itemName"> </td>
</tr>
<tr>
<td>价格</td>
<td><input type="text" style="width: 200px; margin: 0px auto" th:value="${product.price}" id="itemPrice"> </td>
</tr>
<tr>
<td>总数</td>
<td><input type="text" style="width: 200px; margin: 0px auto" th:value="${product.count}" id="itemCount"> </td>
</tr>
</tbody>

 

5、注解模糊查询
http://blog.51cto.com/3316448/2292349
https://www.cnblogs.com/MaxElephant/p/8418276.

@Select("select * from product where name like CONCAT('%',#{name},'%') or id = #{name}")
@ResultType(Product.class)
List<Product> queryByName(@Param("name") String name);

6、表格操作
https://blog.csdn.net/sheypang/article/details/80770618

 

html += "<td>" +
" <input type='button' value='修 改' id='\""+cols[c] +"\"' onclick='javascript:updateItem(this.id)' >" +
" <input type='button' value='删 除' id='\""+cols[c] +"\"' onclick='javascript:deleteItem(this.id)' > "+
" </td>";

html += "</tr>";


7、绑定ENTER事件
// 绑定键盘事件
function query_enter() {
var event=window.event?window.event:event;
if(event.keyCode==13){
query();
}
}

8、刷新父类页面
opener.document.location="/pro/index";

9、公共模板使用

创建header.js文件,写入如下js、css
<script type="text/javascript" src="../../static/js/jquery-1.8.3-min.js"></script>
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

在header中引用
<script type="text/javascript" src="../../static/js/header.js"></script>

 

10、配置文件

 1 #下面这条配置声明了mybatis的配置文件路径,classpath对应的是和这个文件统计的resources
 2 mybatis.config-location=classpath:mybatis-config.xml
 3 
 4 #静态资源文件访问
 5 #spring.mvc.static-path-pattern=/**
 6 spring.resources.static-locations=classpath:/static/js/**
 7 
 8 # default location: src/main/webapp , can be changed
 9 # old version
10 spring.mvc.view.prefix=/WEB-INF/page
11 spring.mvc.view.suffix=.jsp
12 # new version
13 #spring.view.prefix=/
14 #spring.view.suffix=.jsp
15 
16 # thymeleaf
17 spring.thymeleaf.prefix=/WEB-INF/page
18 spring.thymeleaf.suffix=.jsp
19 
20 #测试 参数的调用
21 com.didispace.blog.name=程序员
22 com.didispace.blog.title=SpringBoot
23 com.didispace.blog.desc=${com.didispace.blog.name} is writting 《${com.didispace.blog.title}》
24 
25 #设置编码
26 spring.http.encoding.force=true
27 spring.http.encoding.charset=UTF-8
28 spring.http.encoding.enabled=true
29 server.tomcat.uri-encoding=UTF-8
30 
31 #多环境配置文件属性
32 spring.profiles.active=test
33 
34 # 设置项目名称
35 server.servlet.context-path=/clockck
36 
37 # 多项目部署
38 spring.jmx.enabled=false

 

posted @ 2018-12-29 22:25  Vtianhu  阅读(135)  评论(0编辑  收藏  举报