IntelliJ 설치

https://effectivesquid.tistory.com/entry/intellij%EC%97%90%EC%84%9C-Spring-4-%EC%B4%88%EA%B8%B0-%ED%99%98%EA%B2%BD-%EC%84%B8%ED%8C%85%EC%97%90%EC%84%9C-%EB%94%94%EB%B9%84%EC%97%B0%EB%8F%99%EA%B9%8C%EC%A7%80-%ED%95%9C-%EB%B2%88%EC%97%90-%ED%95%98%EA%B8%B0-Maven-Mysql-Mybatis

세팅 참고하기

https://mvnrepository.com/artifact/org.springframework/spring-context/4.3.30.RELEASE

org.springframework spring-context 4.3.30.RELEASE 만약에 오류나면 C:\Users\Administrator\.m2\repository 여기들어가서 지우셈 https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/4.0.1 javax.servlet jstl 1.2 javax.servlet.jsp jsp-api 2.2 provided org.projectlombok lombok 1.18.20 provided

mysql mysql-connector-java 8.0.25 org.mybatis mybatis 3.5.7 org.mybatis mybatis-spring 2.0.6 com.zaxxer HikariCP 4.0.3

CP - 커넥션풀덕에 소스도 빨라지고 시간 단축됨

shift*2 ->검색
ctrl + shift + A 눌러서
vm 검색하고
Edit Custom VM Options... 클릭하면
텍스트 파일 열리는데 거기서
마지막행 -Dfile.encoding=UTF-8 추가

vm 옵션에
-Dfile.encoding=UTF-8
이거 안해도되나요
거기
맞아요\
위에

그리고 deployment탭에 artifact추가하고
application context: 경로 /로 바꿔줘야
아뇨

된거에요
밑으로 내리면
경로 /로 바꾸면될거같아요
밑으로
스크롤

ctrl alt L -> 개행

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_4_0.xsd"
       version="4.0">

  <display-name>spring1</display-name>
  
  <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>

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

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

  <filter>
   <filter-name>encodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
      </init-param>
  </filter>
  <filter-mapping>
      <filter-name>encodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.koreait</groupId>
  <artifactId>spring1</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
      <maven.compiler.source>8</maven.compiler.source>
      <maven.compiler.target>8</maven.compiler.target>
      <spring-version>4.3.30.RELEASE</spring-version>
  </properties>

  <dependencies>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>${spring-version}</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${spring-version}</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>${spring-version}</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>4.0.1</version>
          <scope>provided</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
      <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.2</version>
          <scope>provided</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
      <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.20</version>
          <scope>provided</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>8.0.25</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
      <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.5.7</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
      <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>2.0.6</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
      <dependency>
          <groupId>com.zaxxer</groupId>
          <artifactId>HikariCP</artifactId>
          <version>4.0.3</version>
      </dependency>

  </dependencies>
</project>

UserController

package com.koreait.spring;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

  @RequestMapping("/login")
  public String login(){
      return "user/login";
  }
}

login.jsp


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>로그인</title>
</head>
<body>
  <h1>로그인</h1>
</body>
</html>

applicationControl

<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"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
  <context:property-placeholder location="classpath:application.properties"/>
  <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
      <property name="driverClassName" value="${db.driver}"/>
      <property name="jdbcUrl" value="${db.host}"/>
      <property name="username" value="${db.username}"/>
      <property name="password" value="${db.password}"/>
  </bean>
  <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
      <constructor-arg ref="hikariConfig"/>
  </bean>
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="typeAliasesPackage" value="com.koreait.spring"/>
  </bean>
</beans>

dispatchServlet

<?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:mvc="http://www.springframework.org/schema/mvc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd">
  <!--MVC 패턴을 사용하고 싶으면( @Controller annotation을 사용하고 싶다면) 적으셈-->
  <mvc:annotation-driven/>
  <!--if you want to use Annotation-->
  <context:annotation-config></context:annotation-config>
  <!--Annotation으로 bean 등록할 클래스들을 스캔뜨는 시작 패키지를 설정-->
  <context:component-scan base-package="com.koreait.spring"/>
  <!--사용할 파일명을 완성해주는 객체-->
  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/"/>
      <property name="suffix" value=".jsp"/>
  </bean>
</beans>

applicationProperties

db.driver=com.mysql.cj.jdbc.Driver
db.host=jdbc:mysql://localhost:3308/board4
db.username=root
db.password=koreait

좋은 웹페이지 즐겨찾기