Skip to content

Commit b113c03

Browse files
committed
[update] format code style
1 parent b3495ce commit b113c03

File tree

88 files changed

+2371
-2493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2371
-2493
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
这套笔记整体偏入门和应用,适合快速上手,对底层实现和机理并未做过多分析。关于 spring 源码的学习笔记,可以参考我的另一个仓库[spring-learning](https://github.com/brianway/spring-learning)
1212

1313

14-
**如果觉得不错,请先在这个仓库上点个star吧**,这也是对我的肯定和鼓励,谢谢了。不定时进行调整和补充,需要关注更新的请 Watch、Star、Fork
14+
**如果觉得不错,请先在这个仓库上点个 star 吧**,这也是对我的肯定和鼓励,谢谢了。不定时进行调整和补充,需要关注更新的请 Watch、Star、Fork
1515

1616
如果你只是单纯要阅读的话,建议移步 CSDN 或者 oschina 上观看,访问速度快很多:
1717

sourcecode/learnssm-firstssm/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<spring.version>4.2.4.RELEASE</spring.version>
1515
</properties>
1616

17-
1817
<dependencies>
1918

2019
<!-- spring框架-->
@@ -78,7 +77,6 @@
7877
<version>1.4</version>
7978
</dependency>
8079

81-
8280
<dependency>
8381
<groupId>log4j</groupId>
8482
<artifactId>log4j</artifactId>
@@ -91,7 +89,6 @@
9189
<version>1.7.18</version>
9290
</dependency>
9391

94-
9592
<!-- JSP tag -->
9693
<dependency>
9794
<groupId>javax.servlet</groupId>
@@ -104,7 +101,6 @@
104101
<version>1.1.2</version>
105102
</dependency>
106103

107-
108104
<!-- hibernate 校验 -->
109105
<dependency>
110106
<groupId>org.hibernate</groupId>
@@ -132,11 +128,6 @@
132128
<version>1.9.13</version>
133129
</dependency>
134130

135-
136-
137131
</dependencies>
138132

139-
140-
141-
142133
</project>

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/controller/ItemsController.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.iot.learnssm.firstssm.controller;
22

3-
43
import com.iot.learnssm.firstssm.controller.converter.validation.ValidGroup1;
5-
import com.iot.learnssm.firstssm.exception.CustomException;
64
import com.iot.learnssm.firstssm.po.ItemsCustom;
75
import com.iot.learnssm.firstssm.po.ItemsQueryVo;
86
import com.iot.learnssm.firstssm.service.ItemsService;
@@ -16,12 +14,12 @@
1614
import org.springframework.web.multipart.MultipartFile;
1715
import org.springframework.web.servlet.ModelAndView;
1816

19-
import javax.servlet.http.HttpServletRequest;
2017
import java.io.File;
2118
import java.util.HashMap;
2219
import java.util.List;
2320
import java.util.Map;
2421
import java.util.UUID;
22+
import javax.servlet.http.HttpServletRequest;
2523

2624
/**
2725
* Created by brian on 2016/3/2.
@@ -53,7 +51,7 @@ public Map<String, String> getItemTypes() {
5351
@RequestMapping("/queryItems")
5452
//实现 对queryItems方法和url进行映射,一个方法对应一个url
5553
//一般建议将url和方法写成一样
56-
public ModelAndView queryItems(HttpServletRequest request, ItemsQueryVo itemsQueryVo) throws Exception{
54+
public ModelAndView queryItems(HttpServletRequest request, ItemsQueryVo itemsQueryVo) throws Exception {
5755
//测试forward后request是否可以共享
5856
//System.out.println(request.getParameter("id"));
5957

@@ -63,7 +61,7 @@ public ModelAndView queryItems(HttpServletRequest request, ItemsQueryVo itemsQue
6361
//返回ModelAndView
6462
ModelAndView modelAndView = new ModelAndView();
6563
//相当于request的setAttribute方法,在jsp页面中通过itemsList取数据
66-
modelAndView.addObject("itemsList",itemsList);
64+
modelAndView.addObject("itemsList", itemsList);
6765

6866
//指定视图
6967
//下边的路径,如果在视图解析器中配置jsp的路径前缀和后缀,修改为items/itemsList
@@ -74,7 +72,6 @@ public ModelAndView queryItems(HttpServletRequest request, ItemsQueryVo itemsQue
7472
return modelAndView;
7573
}
7674

77-
7875
//商品信息修改页面显示
7976
//@RequestMapping("/editItems")
8077
//限制http请求方法,可以post和get
@@ -96,18 +93,18 @@ public ModelAndView editItems()throws Exception {
9693
return modelAndView;
9794
}*/
9895

99-
@RequestMapping(value="/editItems",method={RequestMethod.POST,RequestMethod.GET})
96+
@RequestMapping(value = "/editItems", method = {RequestMethod.POST, RequestMethod.GET})
10097
//@RequestParam里边指定request传入参数名称和形参进行绑定。
10198
//通过required属性指定参数是否必须要传入
10299
//通过defaultValue可以设置默认值,如果id参数没有传入,将默认值和形参绑定。
103-
public String editItems(Model model,@RequestParam(value="id",required=true) Integer items_id)throws Exception {
100+
public String editItems(Model model, @RequestParam(value = "id", required = true) Integer items_id) throws Exception {
104101

105102
//调用service根据商品id查询商品信息
106103
ItemsCustom itemsCustom = itemsService.findItemsById(items_id);
107104

108105
//判断商品是否为空,根据id没有查询到商品,抛出异常,提示用户商品信息不存在
109106
//if(itemsCustom == null){
110-
//throw new CustomException("修改的商品信息不存在!");
107+
//throw new CustomException("修改的商品信息不存在!");
111108
//}
112109

113110
//通过形参中的model将model数据传到页面
@@ -122,7 +119,9 @@ public String editItems(Model model,@RequestParam(value="id",required=true) Inte
122119
//@PathVariable中名称要和占位符一致,形参名无需和其一致
123120
//如果占位符中的名称和形参名一致,在@PathVariable可以不指定名称
124121
@RequestMapping("/itemsView/{id}")
125-
public @ResponseBody ItemsCustom itemsView(@PathVariable("id") Integer items_id)throws Exception{
122+
public
123+
@ResponseBody
124+
ItemsCustom itemsView(@PathVariable("id") Integer items_id) throws Exception {
126125

127126
//调用service查询商品信息
128127
ItemsCustom itemsCustom = itemsService.findItemsById(items_id);
@@ -131,8 +130,6 @@ public String editItems(Model model,@RequestParam(value="id",required=true) Inte
131130

132131
}
133132

134-
135-
136133
// 商品信息修改提交
137134
// 在需要校验的pojo前边添加@Validated,在需要校验的pojo后边添加BindingResult
138135
// bindingResult接收校验出错信息
@@ -144,17 +141,17 @@ public String editItemsSubmit(
144141
HttpServletRequest request,
145142
Integer id,
146143
@ModelAttribute("items")
147-
@Validated(value = ValidGroup1.class)ItemsCustom itemsCustom,
144+
@Validated(value = ValidGroup1.class) ItemsCustom itemsCustom,
148145
BindingResult bindingResult,
149146
MultipartFile items_pic
150-
)throws Exception {
147+
) throws Exception {
151148

152149
//获取校验错误信息
153-
if(bindingResult.hasErrors()){
150+
if (bindingResult.hasErrors()) {
154151
// 输出错误信息
155152
List<ObjectError> allErrors = bindingResult.getAllErrors();
156153

157-
for (ObjectError objectError :allErrors){
154+
for (ObjectError objectError : allErrors) {
158155
// 输出错误信息
159156
System.out.println(objectError.getDefaultMessage());
160157
}
@@ -171,16 +168,15 @@ public String editItemsSubmit(
171168
//原始名称
172169
String originalFilename = items_pic.getOriginalFilename();
173170
//上传图片
174-
if(items_pic!=null && originalFilename!=null && originalFilename.length()>0){
171+
if (items_pic != null && originalFilename != null && originalFilename.length() > 0) {
175172

176173
//存储图片的物理路径
177174
String pic_path = "D:\\tmp\\";
178175

179-
180176
//新的图片名称
181177
String newFileName = UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
182178
//新图片
183-
File newFile = new File(pic_path+newFileName);
179+
File newFile = new File(pic_path + newFileName);
184180

185181
//将内存中的数据写入磁盘
186182
items_pic.transferTo(newFile);
@@ -200,7 +196,6 @@ public String editItemsSubmit(
200196

201197
}
202198

203-
204199
//商品信息修改提交
205200
//@RequestMapping("/editItemsSubmit")
206201
//public ModelAndView editItemsSubmit(HttpServletRequest request, Integer id, ItemsCustom itemsCustom)throws Exception {
@@ -215,8 +210,6 @@ public String editItemsSubmit(
215210
// return modelAndView;
216211
//}
217212

218-
219-
220213
////商品信息修改提交
221214
//@RequestMapping("/success")
222215
//public ModelAndView success(){
@@ -227,7 +220,6 @@ public String editItemsSubmit(
227220
// return modelAndView;
228221
//}
229222

230-
231223
// 批量删除 商品信息
232224
@RequestMapping("/deleteItems")
233225
public String deleteItems(Integer[] items_id) throws Exception {
@@ -240,18 +232,17 @@ public String deleteItems(Integer[] items_id) throws Exception {
240232

241233
}
242234

243-
244235
// 批量修改商品页面,将商品信息查询出来,在页面中可以编辑商品信息
245236
@RequestMapping("/editItemsQuery")
246-
public ModelAndView editItemsQuery(HttpServletRequest request, ItemsQueryVo itemsQueryVo) throws Exception{
237+
public ModelAndView editItemsQuery(HttpServletRequest request, ItemsQueryVo itemsQueryVo) throws Exception {
247238

248239
//调用service查找数据库,查询商品列表
249240
List<ItemsCustom> itemsList = itemsService.findItemsList(itemsQueryVo);
250241

251242
//返回ModelAndView
252243
ModelAndView modelAndView = new ModelAndView();
253244
//相当于request的setAttribute方法,在jsp页面中通过itemsList取数据
254-
modelAndView.addObject("itemsList",itemsList);
245+
modelAndView.addObject("itemsList", itemsList);
255246

256247
modelAndView.setViewName("items/editItemsQuery");
257248

@@ -266,5 +257,4 @@ public String editItemsAllSubmit(ItemsQueryVo itemsQueryVo) throws Exception {
266257
return "success";
267258
}
268259

269-
270260
}

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/controller/JsonTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ public class JsonTest {
1515
//@RequestBody将请求的商品信息的json串转成itemsCustom对象
1616
//@ResponseBody将itemsCustom转成json输出
1717
@RequestMapping("/requestJson")
18-
public @ResponseBody ItemsCustom requestJson(@RequestBody ItemsCustom itemsCustom){
18+
public
19+
@ResponseBody
20+
ItemsCustom requestJson(@RequestBody ItemsCustom itemsCustom) {
1921

2022
//@ResponseBody将itemsCustom转成json输出
2123
return itemsCustom;
2224
}
2325

2426
//请求key/value,输出json
2527
@RequestMapping("/responseJson")
26-
public @ResponseBody ItemsCustom responseJson(ItemsCustom itemsCustom){
28+
public
29+
@ResponseBody
30+
ItemsCustom responseJson(ItemsCustom itemsCustom) {
2731

2832
//@ResponseBody将itemsCustom转成json输出
2933
return itemsCustom;
3034
}
3135

32-
33-
34-
3536
}

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/controller/MyJsonTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ public class MyJsonTest {
1919
private ItemsService itemsService;
2020

2121
@RequestMapping("/testJson")
22-
public @ResponseBody
23-
Object responseJson()throws Exception {
24-
class ResponseBody{
25-
String code="10000";
26-
String message= "成功";
27-
Map<String,Object>result = new HashMap<String, Object>();
28-
29-
public Map<String, Object> getResult(){
30-
return result;
22+
public
23+
@ResponseBody
24+
Object responseJson() throws Exception {
25+
class ResponseBody {
26+
String code = "10000";
27+
String message = "成功";
28+
Map<String, Object> result = new HashMap<String, Object>();
29+
30+
public Map<String, Object> getResult() {
31+
return result;
3132
}
3233

3334
public void setResult(Map<String, Object> result) {
@@ -51,10 +52,9 @@ public void setMessage(String message) {
5152
}
5253
}
5354

54-
5555
ResponseBody responseBody = new ResponseBody();
5656
ItemsCustom itemsCustom = itemsService.findItemsById(1);
57-
responseBody.getResult().put("itemsCustom",itemsCustom);
57+
responseBody.getResult().put("itemsCustom", itemsCustom);
5858
return responseBody;
5959

6060
}

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/controller/converter/CustomDateConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Created by brian on 2016/3/5.
1111
*/
12-
public class CustomDateConverter implements Converter<String,Date>{
12+
public class CustomDateConverter implements Converter<String, Date> {
1313
public Date convert(String s) {
1414
//实现 将日期串转成日期类型(格式是yyyy-MM-dd HH:mm:ss)
1515

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/controller/converter/validation/ValidGroup1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created by brian on 2016/3/6.
55
*/
66
public interface ValidGroup1 {
7-
//接口中不需要定义任何方法,仅是对不同的校验规则进行分组
8-
//此分组只校验商品名称长度
7+
//接口中不需要定义任何方法,仅是对不同的校验规则进行分组
8+
//此分组只校验商品名称长度
99

1010
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.iot.learnssm.firstssm.controller.converter.validation;
22

3-
43
/**
54
* Created by brian on 2016/3/6.
65
*/
76
public interface ValidGroup2 {
8-
//接口中不需要定义任何方法,仅是对不同的校验规则进行分组
7+
//接口中不需要定义任何方法,仅是对不同的校验规则进行分组
98

109
}

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/exception/CustomException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*
66
* 系统 自定义异常类,针对预期的异常,需要在程序中抛出此类的异常
77
*/
8-
public class CustomException extends Exception{
8+
public class CustomException extends Exception {
99
//异常信息
1010
public String message;
1111

12-
public CustomException(String message){
12+
public CustomException(String message) {
1313
super(message);
1414
this.message = message;
1515
}
@@ -22,6 +22,5 @@ public void setMessage(String message) {
2222
this.message = message;
2323
}
2424

25-
2625
}
2726

sourcecode/learnssm-firstssm/src/main/java/com/iot/learnssm/firstssm/exception/CustomExceptionResolver.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
/**
1010
* Created by brian on 2016/3/7.
1111
*/
12-
public class CustomExceptionResolver implements HandlerExceptionResolver{
12+
public class CustomExceptionResolver implements HandlerExceptionResolver {
1313
/**
14-
*
1514
* @param request
1615
* @param response
1716
* @param handler
@@ -24,17 +23,17 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
2423
//如果该 异常类型是系统 自定义的异常,直接取出异常信息,在错误页面展示
2524
//String message = null;
2625
//if(ex instanceof CustomException){
27-
//message = ((CustomException)ex).getMessage();
26+
//message = ((CustomException)ex).getMessage();
2827
//}else{
29-
////如果该 异常类型不是系统 自定义的异常,构造一个自定义的异常类型(信息为“未知错误”)
30-
//message="未知错误";
28+
////如果该 异常类型不是系统 自定义的异常,构造一个自定义的异常类型(信息为“未知错误”)
29+
//message="未知错误";
3130
//}
3231

3332
//上边代码变为
3433
CustomException customException;
35-
if(ex instanceof CustomException){
36-
customException = (CustomException)ex;
37-
}else{
34+
if (ex instanceof CustomException) {
35+
customException = (CustomException) ex;
36+
} else {
3837
customException = new CustomException("未知错误");
3938
}
4039

@@ -49,7 +48,6 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
4948
//指向错误页面
5049
modelAndView.setViewName("error");
5150

52-
5351
return modelAndView;
5452

5553
}

0 commit comments

Comments
 (0)