spring-boot&mvn&terminal

起因

下午再看git,看了半天还是感觉有很多不懂的东西,用的时候再说吧;

Maven

  1. maven原来没有配置过,直接用的Intellij 自己的,所以自然也不知到人家命令行是啥情况了呗;所以maven应该先下载,配置环境变量,然后就可以用命令行了;

Terminal

  1. 一直以来都不咋会用命令行,结果今天发现cmd是可以直接运行git,maven命令的,也就是配置环境的作用?
  2. Intellij 中terminal是有问题的,因为win10命令行是新的,没法用的说,所以需要使用旧版控制台;
  3. powershell 也可以修改配色啥的,以后用用那个也不错的;

Spring-boot

  1. @SpringBootApplication
/**
 * main函数 SpringBootApplication 是<br>
 * 三个命令的替代写法
 */
@SpringBootApplication
public class WendaApplication {

    public static void main(String[] args) {
        SpringApplication.run(WendaApplication.class, args);
    }
}
  1. 自动装配
   @Autowired
    WendaService wendaService;              //自动装配
  1. 3.
    /**
     * 通过path,可以指定多个路径到一个页面,method可以指定该页面的HTTP方法<br>
     * ResponseBody 表示该方法的返回结果直接写入HTTP response body<br>
     * 不调用静态模板,不会加载jsp啥的
     * @return 返回结果直接写入response body
     */
    @RequestMapping(path = {"/", "/index"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String index(HttpSession httpSession) {
        LOGGER.info("visit"+new Date());
        return "Hello World" + httpSession.getAttribute("msg");
    }
  1. PathVariable,RequestParam
    PathVariable,是从路径信息得到的变量 比如 *.net/admin/1; admin和1都可以认为是路劲变量
    RequestParam 是request变量,跟着请求一起发来, ?type = 1;type通过链接传递参数,作为request变量;

    /**
     * PathVariable    是指从路径得到的参数 <br>
     * RequestParam    是指从请求得到的参数
     *
     * @param userId  用户Id
     * @param groupId 用户组
     * @param type    类型
     * @param key     key
     * @return 返回结果直接写入response body
     */
    @RequestMapping(path = {"/profile/{groupId}/{userId}"})
    @ResponseBody
    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);
    }
  1. 报头,cookie
  /**
     * 打印了从cookie获取数据<br>
     * 打印了请求头<br>
     * response 添加了一个Header,添加了一个cookie
     * @param response  响应
     * @param request   请求
     * @param sessionId 从cookie获取的id
     * @return
     */
    @RequestMapping(path = {"/request"}, method = {RequestMethod.GET})
    @ResponseBody
    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();
    }

面向切面编程

  1. before &after
@Aspect
@Component
public class LogAspect {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);

    /**
     * 打印连接点的一大堆信息,before在方法调用前执行
     * @param joinPoint 连接点
     */
    @Before("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());

    }
    @After("execution(* cn.colining.controller.IndexController.*(..))")
    public void  afterMethod(){
        LOGGER.info("after method"+new Date());

    }
}

freemarker

<html>
Hello!
<body>
<pre>
    <#--通过${xxx} 来表示变量-->
    ${value1}

    <#--colors是从后台传来的对象,和foreach语法类似-->
    <#list colors as color>
        color ${color} ${color_index}
    </#list>
    <#--map是后台对象,?key是map固定写法-->
    <#list  map?keys as key>
        key --> ${key}
        value --> ${map[key]}
    </#list>
    <#--得到属性的两种方法-->
    ${user.name}
    ${user.getDescription()}

    <#--声明变量-->
    <#assign title= 5>
    ${title}
    <#--在本页面加入其他页面-->
    <#include "header.ftl">

    <#--定义宏,colortest是宏的名字,color和index是参数-->
    <#macro colortest color index>
        render_macro: ${color} ,${index}
    </#macro>
    <#--相当于遍历时调用函数,注意参数不需要加${},我也不知道为啥-->
    <#list colors as color>
        <@colortest color =color index = color_index>
        </@colortest>
    </#list>

    <#macro greet a>
        <font size=’+2’>HelloW Joe! ${a}</font>
    </#macro>
    <@greet a =title></@greet>

    <#--可以通过已定义变量定义新的变量-->
    <#assign hello = "hello">
    <#assign helloWorld1 = "${hello}1 world">
    <#assign helloWorld2 = '${hello}2 world'>
    ${helloWorld1}
    ${helloWorld2}
</pre>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值