Skip to content

Commit

Permalink
moidfy
Browse files Browse the repository at this point in the history
  • Loading branch information
leechenxiang committed Dec 10, 2017
1 parent 8639697 commit 5772071
Show file tree
Hide file tree
Showing 13 changed files with 523 additions and 483 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- 引入log4j日志依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/imooc/config/WebMvcConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public void addInterceptors(InterceptorRegistry registry) {
/**
* 拦截器按照顺序执行
*/
registry.addInterceptor(new OneInterceptor()).addPathPatterns("/one/**")
.addPathPatterns("/two/**");
registry.addInterceptor(new TwoInterceptor()).addPathPatterns("/two/**");
registry.addInterceptor(new TwoInterceptor()).addPathPatterns("/two/**")
.addPathPatterns("/one/**");
registry.addInterceptor(new OneInterceptor()).addPathPatterns("/one/**");

super.addInterceptors(registry);
}
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/com/imooc/controller/FreemarkerController.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package com.imooc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.imooc.pojo.Resource;

@Controller
@RequestMapping("ftl")
public class FreemarkerController {

@Autowired
private Resource resource;

@RequestMapping("/index")
public String index(ModelMap map) {
map.addAttribute("resource", resource);
return "freemarker/index";
}

@RequestMapping("center")
public String center() {
return "freemarker/center/center";
}

package com.imooc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.imooc.pojo.Resource;

@Controller
@RequestMapping("ftl")
public class FreemarkerController {

@Autowired
private Resource resource;

@RequestMapping("/index")
public String index(ModelMap map) {
map.addAttribute("resource", resource);
return "freemarker/index";
}

@RequestMapping("center")
public String center() {
return "freemarker/center/center";
}

}
62 changes: 31 additions & 31 deletions src/main/java/com/imooc/controller/HelloContoller.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package com.imooc.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.pojo.IMoocJSONResult;
import com.imooc.pojo.Resource;

@RestController
public class HelloContoller {

@Autowired
private Resource resource;

@RequestMapping("/hello")
public Object hello() {
return "hello springboot~~";
}

@RequestMapping("/getResource")
public IMoocJSONResult getResource() {

Resource bean = new Resource();
BeanUtils.copyProperties(resource, bean);

return IMoocJSONResult.ok(bean);
}

}
package com.imooc.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.pojo.IMoocJSONResult;
import com.imooc.pojo.Resource;

@RestController
public class HelloContoller {

@Autowired
private Resource resource;

@RequestMapping("/hello")
public Object hello() {
return "hello springboot~~";
}

@RequestMapping("/getResource")
public IMoocJSONResult getResource() {

Resource bean = new Resource();
BeanUtils.copyProperties(resource, bean);

return IMoocJSONResult.ok(bean);
}

}
156 changes: 78 additions & 78 deletions src/main/java/com/imooc/controller/ThymeleafController.java
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package com.imooc.controller;

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

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.imooc.pojo.User;

@Controller
@RequestMapping("th")
public class ThymeleafController {

@RequestMapping("/index")
public String index(ModelMap map) {
map.addAttribute("name", "thymeleaf-imooc");
return "thymeleaf/index";
}

@RequestMapping("center")
public String center() {
return "thymeleaf/center/center";
}

@RequestMapping("test")
public String test(ModelMap map) {

User u = new User();
u.setName("superadmin");
u.setAge(10);
u.setPassword("123465");
u.setBirthday(new Date());
u.setDesc("<font color='green'><b>hello imooc</b></font>");

map.addAttribute("user", u);

User u1 = new User();
u1.setAge(19);
u1.setName("imooc");
u1.setPassword("123456");
u1.setBirthday(new Date());

User u2 = new User();
u2.setAge(17);
u2.setName("LeeCX");
u2.setPassword("123456");
u2.setBirthday(new Date());

List<User> userList = new ArrayList<>();
userList.add(u);
userList.add(u1);
userList.add(u2);

map.addAttribute("userList", userList);

return "thymeleaf/test";
}

@PostMapping("postform")
public String postform(User u) {

System.out.println("姓名:" + u.getName());
System.out.println("年龄:" + u.getAge());

return "redirect:/th/test";
}

@RequestMapping("showerror")
public String showerror(User u) {

int a = 1 / 0;

return "redirect:/th/test";
}
package com.imooc.controller;

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

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.imooc.pojo.User;

@Controller
@RequestMapping("th")
public class ThymeleafController {

@RequestMapping("/index")
public String index(ModelMap map) {
map.addAttribute("name", "thymeleaf-imooc");
return "thymeleaf/index";
}

@RequestMapping("center")
public String center() {
return "thymeleaf/center/center";
}

@RequestMapping("test")
public String test(ModelMap map) {

User u = new User();
u.setName("superadmin");
u.setAge(10);
u.setPassword("123465");
u.setBirthday(new Date());
u.setDesc("<font color='green'><b>hello imooc</b></font>");

map.addAttribute("user", u);

User u1 = new User();
u1.setAge(19);
u1.setName("imooc");
u1.setPassword("123456");
u1.setBirthday(new Date());

User u2 = new User();
u2.setAge(17);
u2.setName("LeeCX");
u2.setPassword("123456");
u2.setBirthday(new Date());

List<User> userList = new ArrayList<>();
userList.add(u);
userList.add(u1);
userList.add(u2);

map.addAttribute("userList", userList);

return "thymeleaf/test";
}

@PostMapping("postform")
public String postform(User u) {

System.out.println("姓名:" + u.getName());
System.out.println("年龄:" + u.getAge());

return "redirect:/th/test";
}

@RequestMapping("showerror")
public String showerror(User u) {

int a = 1 / 0;

return "redirect:/th/test";
}
}
Loading

0 comments on commit 5772071

Please sign in to comment.