Idea 學習筆記

學習娛樂筆記

1.idea 創建一個 項目->devicemanager

   遇到的問題:1.設置tomcat 的時候,no  artifact configered

添加之後就可以了。

2.hello world 跑不起來

可以看到白色字體的錯誤:com.intellij.execution.ExecutionException: D:\Ide\work-space\device_manager\out\artifacts\Devicemanager not found for the web module.

解決辦法:

 

確定的時候好像有一個警告,點fix

 3.這些做完之後運行,一直404,找不到界面

 

我的是這個路徑錯誤了

 

不知道爲什麼默認的路徑是下面那個 web,改成src->main 裏面的之後再運行就好了。下面那個web沒有存在的必要,刪除!

 

總算是爬出了 hello world 的坑,一般不需要自己創建項目,都是別人配置完之後直接跑,但是自己玩的話->心累。

4.配置SSM SpringMvc +Spring +Mybatis

 

進去之後選spring 和它下面的springmvc

配置一下web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <display-name>Archetype Created Web Application</display-name>

  <!--welcome pages-->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!--配置springmvc DispatcherServlet-->
  <servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <!--配置dispatcher.xml作爲mvc的配置文件-->
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!--把applicationContext.xml加入到配置文件中-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

 上面是從網上抄的

dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--此文件負責整個mvc中的配置-->

    <!--啓用spring的一些annotation -->
    <context:annotation-config/>

    <!-- 配置註解驅動 可以將request參數與綁定到controller參數上 -->
    <mvc:annotation-driven/>

    <!--靜態資源映射-->
    <!--本項目把靜態資源放在了webapp的statics目錄下,資源映射如下-->
    <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css/"/>
    <mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/"/>
    <mvc:resources mapping="/image/**" location="/WEB-INF/statics/image/"/>

    <!-- 對模型視圖名稱的解析,即在模型視圖名稱添加前後綴(如果最後一個還是表示文件夾,則最後的斜槓不要漏了) 使用JSP-->
    <!-- 默認的視圖解析器 在上邊的解析錯誤時使用 (默認使用html)- -->
    <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/view/"/><!--設置JSP文件的目錄位置-->
        <property name="suffix" value=".jsp"/>
        <property name="exposeContextBeansAsAttributes" value="true"/>
    </bean>

    <!-- 自動掃描裝配 -->
    <context:component-scan base-package="com.dev_manager.controller"/>
</beans>

弄完之後報錯 說 URI not registered,網上查了好多,有人說alt+enter ->fetch 就好了,但是那個spring-context.xsd 我獲取不到,最後發現我所有pom添加的依賴都沒有引入進來、

勾了自動導入之後就行了 

5.創建jdbc.properties 由於之前是創建的file 文件,不是選的 resbundle ,導致後面引入的時候說 資源不匹配。

對比下 log4j 的配置,兩個文件的區別一目瞭然,本想刪了重建,但是刪了之後創建resbundle 的時候永遠提示 文件已存在,然後自動給我生成一個新的,沒辦法,只好suppress,讓它不要報紅,報紅看着挺難受的

6.靜態資源映射

<!--本項目把靜態資源放在了webapp的statics目錄下,資源映射如下-->
    <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css/"/>
    <mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/"/>
    <mvc:resources mapping="/image/**" location="/WEB-INF/statics/image/"/>
    <mvc:resources mapping="/lib/**" location="/WEB-INF/statics/lib/"/>

用的時候直接 /css/ 就好了

 

總結:這個hello world 程序比android 複雜多了,要手動配置很多東西,感覺其實可以做一個插件,創建項目的時候自動生成這些配置項和配置文件,因爲每個公司都有自己的後臺模式,但使用一套東西總比下面的人胡亂配置要好。

爬出了hello world 的坑了,可是自己寫項目的話,包括了 數據庫設計,頁面設計,想想都不想寫了。萬事開頭難,慢慢來吧,一着急都想放棄了,希望有一天可以  後臺+前端+移動端 發表自己的個人項目,而不是想寫個程序發現要後臺。

順便吐槽公司後臺,難產,app基本做完半年了,後臺還沒動靜,馬上交貨了,還沒有一個能看的界面,讓我做個自動更新功能,數據都沒有,完全用不了吧。算了,想想我只是個小兵,應該不會在這裏多久了。兵熊熊一個,將熊熊一窩,下次希望找個靠譜的領導。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章