uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

intellij idea #59

Open uniquejava opened 8 years ago

uniquejava commented 8 years ago

IDEA 2016.1 (maven + spring mvc + tomcat + debug)

  1. New empty maven project and Finish (Enable Auto Import in the hint dialog)
  2. Paste into pom.xml spring-webmvc, you can use auto completion here(All you need to type are: <dep, dep, spring-webmvc, org, ctrl+option+right, 4.2.6.RELEASE
  3. Expand your project, you can see the standard maven directories and libraries are created/downloaded.
  4. Add framework support > Web Application + Spring MVC
  5. mkdir src/main/webapp and drag the WEB-INF into it, lastly delete the generated web.
  6. New jsp WEB-INF/views/hello.jsp
  7. Change project structure[cmd+;] > modules > web > web resource directories to this new location.
  8. New class: com.cyper.controller.HelloController.
  9. WEB-INF > New Xml > Spring Config > spring-servlet.xml. (note when editing this file, the xml namespace declaration part can be auto added by idea, you can just type <context:com and <mvc:ann to have it auto completed). (This creating xml file step is optional, you can modify the generated dispatcher-servlet.xml if exists)
  10. File --> Project Structure --> Artifacts > Select all the maven dependencies from right side > right click --> Put into WEB-INF/lib
  11. Toolbar > Edit configurations > Plus > type "tom" to search and select tomcat servers > local > Deployment > click Plus button > Artifact... > keep the war exploded as it is > Click Finish
  12. Edit configurations Again, this time, you need to set on update action: update classes and resources, on frame deactivation: update resources
  13. Now you can debug you application by click the debug button.

Now if you change JSP you don't have to restart anything, just refresh the browser and if you change class Cmd + F10 or Run > Reload Changed Classes and If you add new methods for a class you may need to Cmd + F10 > Redeploy

Note: the default contextConfigLocation for spring mvc is /WEB-INF/SERVLETNAME-servet.xml, if you are using this exact name, you don't have to specify it in web.xml

pom.xml

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

HelloController.java

@Controller
public class HelloController {
    @RequestMapping("/")
    public String hello(){
        return "hello";
    }
}

web.xml

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

spring-servlet.xml

    <context:component-scan base-package="com.cyper.controllers"/>

    <mvc:annotation-driven/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

References:

http://stackoverflow.com/questions/20689658/intellij-idea-how-to-update-resources-on-a-local-server-tomcat

http://stackoverflow.com/questions/24682366/automatic-reloading-of-java-class-resources-in-intellij-idea

https://github.com/marley-spring/Building-an-e-commerce-store-using-java-spring-framework

https://www.mobibrw.com/2016/3494

uniquejava commented 8 years ago

keymap modifications (webstorm, idea)

使用了IDEA自带的keymap, 仅对个别认为不合理的快捷键做了修正:(原则是尽量保持默认设置, 改动越少越好!)

  1. Delete Line: ⌘ + del ->⌘ + d (单手操作删除当前行或多行代码, 将其修改为⌘+d, 同Eclipse)
  2. Duplicate Lines: ⌘+d -> ⌘+⇧+d (删除行比重复行更常用, 理应使用更短的快捷键)
  3. Navigate File: ⌘+⇧+o -> ⌘+p (我经常在chrome中做调试, 改成了和chrome一致的快捷键. chrome没法改快捷键,  只好牺牲IDEA)
  4. 定位方法, 同上, 这个叫File Structure, 默认为⌘+F12,(太远了), 我将其修改为⌘+⇧+o (和chrome保持一致)
  5. Reformat Code: ⌘ + ⇧ + F 我有代码洁癖, 希望能单手完成这个操作, 同Eclipse
  6. Find in Path: ⌘ + H , 为了解决上一步的Conflicts, 同Eclipse
  7. Switch Frame: ⌘ + 2 (需要先安装Frame Switcher插件)
  8. ⌘ +  up找定义, ⌘ + down找usage

默认的很有用的

.. 待续 ..

IDEA 2016.1.3

我目前用的2016.1.3版本, 有效期到2099

打开类 ⌘+n 打开文件 ⌘+shift+n 关闭tab 改成了⌘+w Extend Selection从先前的⌘+w改成了ctrl+w

uniquejava commented 8 years ago

live template

打开zen html中的c 修改为在xml中也能使用.

Editor>JavaScript>Spaces>Within: ES6 import/export braces

uniquejava commented 5 years ago

配置国化化

Thank you very very much, solved by just checking "Transparent native-to-ascii conversion" on File Encoding settings as you mentioned.

Thanks again!

来源: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206842645-Resource-bundle-editor-not-working