起因
下午再看git,看了半天还是感觉有很多不懂的东西,用的时候再说吧;
Maven
- maven原来没有配置过,直接用的Intellij 自己的,所以自然也不知到人家命令行是啥情况了呗;所以maven应该先下载,配置环境变量,然后就可以用命令行了;
Terminal
- 一直以来都不咋会用命令行,结果今天发现cmd是可以直接运行git,maven命令的,也就是配置环境的作用?
- Intellij 中terminal是有问题的,因为win10命令行是新的,没法用的说,所以需要使用旧版控制台;
- powershell 也可以修改配色啥的,以后用用那个也不错的;
Spring-boot
@SpringBootApplication
1234567891011/*** main函数 SpringBootApplication 是<br>* 三个命令的替代写法*/public class WendaApplication {public static void main(String[] args) {SpringApplication.run(WendaApplication.class, args);}}自动装配
12WendaService wendaService; //自动装配- 123456789101112/*** 通过path,可以指定多个路径到一个页面,method可以指定该页面的HTTP方法<br>* ResponseBody 表示该方法的返回结果直接写入HTTP response body<br>* 不调用静态模板,不会加载jsp啥的* @return 返回结果直接写入response body*/"/", "/index"}, method = {RequestMethod.POST, RequestMethod.GET})(path = {public String index(HttpSession httpSession) {LOGGER.info("visit"+new Date());return "Hello World" + httpSession.getAttribute("msg");}
PathVariable,RequestParam
PathVariable,是从路径信息得到的变量 比如 *.net/admin/1; admin和1都可以认为是路劲变量
RequestParam 是request变量,跟着请求一起发来, ?type = 1;type通过链接传递参数,作为request变量;1234567891011121314151617181920/*** PathVariable 是指从路径得到的参数 <br>* RequestParam 是指从请求得到的参数** @param userId 用户Id* @param groupId 用户组* @param type 类型* @param key key* @return 返回结果直接写入response body*/"/profile/{groupId}/{userId}"})(path = {public String profile(@PathVariable("userId") int userId,@PathVariable("groupId") String groupId,@RequestParam(value = "type", defaultValue = "1", required = true) int type,@RequestParam(value = "key", defaultValue = "zz", required = false) String key) {return String.format("Profile Page of %s %d,<br> t: %d k: %s", groupId, userId, type, key);}报头,cookie
12345678910111213141516171819202122232425262728293031323334353637383940414243/*** 打印了从cookie获取数据<br>* 打印了请求头<br>* response 添加了一个Header,添加了一个cookie* @param response 响应* @param request 请求* @param sessionId 从cookie获取的id* @return*/"/request"}, method = {RequestMethod.GET})(path = {public String template( HttpServletResponse response,HttpServletRequest request,@CookieValue("JSESSIONID") String sessionId) {StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("COOKIEVALUE" + " " + sessionId+"<br>");Enumeration<String> headerNames = request.getHeaderNames();while (headerNames.hasMoreElements()) {String name = headerNames.nextElement();stringBuilder.append(name + ":" + request.getHeader(name) + "<br>");}if (request.getCookies() != null) {for (Cookie cookie : request.getCookies()) {stringBuilder.append("Cookie:" + cookie.getName() + "value" + cookie.getValue());}}stringBuilder.append(request.getMethod() + "<br>");stringBuilder.append(request.getQueryString() + "<br>");stringBuilder.append(request.getPathInfo() + "<br>");stringBuilder.append(request.getRequestURI() + "<br>");response.addHeader("colin", "hello");response.addCookie(new Cookie("username", "colin"));// try {// response.sendRedirect("/index");// } catch (IOException e) {// e.printStackTrace();// }return stringBuilder.toString();}
面向切面编程
- before &after123456789101112131415161718192021222324public class LogAspect {private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);/*** 打印连接点的一大堆信息,before在方法调用前执行* @param joinPoint 连接点*/"execution(* cn.colining.controller.*Controller.*(..))")(public void beforeMethod(JoinPoint joinPoint) {StringBuilder stringBuilder = new StringBuilder();for (Object o : joinPoint.getArgs() ) {stringBuilder.append("arg: " + o.toString() + "|");}LOGGER.info("before method "+stringBuilder.toString());}"execution(* cn.colining.controller.IndexController.*(..))")(public void afterMethod(){LOGGER.info("after method"+new Date());}}
freemarker
|
|