반응형

pom.xml에 의존성 추가

<dependency> 
  <groupId>org.springframework</groupId> 
  <artifactId>spring-test</artifactId> 
  <version>5.0.7.RELEASE</version> 
</dependency>
반응형
반응형

 

id 값을 받아와서 id 별 상세보기 페이지를 만드려고 했는데 계속 SQL 문법 오류가 났다..

다시 이 실수를 하지 않기 위해서 정리

Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 ### The error may exist in com/example/demo/dao/ArticleDao.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT * FROM article WHERE id = {#id }; ### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 ### The error may exist in com/example/demo/dao/ArticleDao.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT * FROM article WHERE id = {#id };

 

Dao.Java

파라미터를 쓰기 위해서 @Param 어노테이션이 필요함

Article getArticleById(@Param("id") int id);

 

Dao.xml

맵퍼에서는 속성 명 = #{파라미터 명} 이렇게 사용한다.

<select id="getArticleById" resultType="Article">
    SELECT * 
    FROM article 
    WHERE id = #{id }
</select>


어이없게도 나는 id = {# id } 이런 식으로 작성해서 틀렸던 것..!

반응형
반응형

 

다시 돌아가서 연습해보려니깐 이 전 커밋으로 돌아가는 코드가 필요해서 정리!

 

 

git checkout 커밋번호 -f

 

밑줄 친 곳은 커밋번호를 넣어주면 되는데

 

빨간 박스를 누르고 

돌아가고 싶은 지점을 클릭 후

 

우측에서 커밋 번호를 얻을 수 있다.

 

나는 파일 정리라고 커밋 메시지를 남긴 지점으로 체크아웃함!

반응형
반응형

1. Controller 

컨트롤러가 url 받아서 요청 실행

컨트롤러에 있는 articleSerivce -> 2번으로

List<Article> articles = articleService.getArticles();

 

//하드코딩하면 이런 식

List<Article> showList() {
    List<Article> articles = new ArrayList<>();
    articles.add(1,"2020-05-29","2020-05-29","제목","내용")
    
    return articles;
}

2. Article.java

 

일단 컨트롤러에 Article 없으니 만들어 주자

데이터베이스에 있는 속성들을 다 적어줘야한다.

@Data

@AllArgsConstrutor 

국룰

 

3. Serivce 

** 서비스가 컨트롤러에게 요청하는 경우는 절대 없다. 무조건 컨트롤러 > 서비스 흐름 

** @Service 꼭 삽입

 

return articleDao.getArticles();

서비스에 있는 DAO로 요청

 

 

4. articleDao

 

DAO는 Database와 통신하는 역할 수행

 

** @Mapper 꼭 삽입

 

** articleDao.xml 쌍둥이 : articleDao.java에 메서드가 있으면 articleDao.xml에도 꼭 맞는 SELECT 엘리멘트가  있어야 함.

// articleDao.java
@Mapper
public interface ArticleDao {
List<Article> getArticles();
}
-- articleDao.xml
<mapper namespace="com.example.demo.dao.ArticleDao">
    <select id="getArticles" resultType="Article">
        SELECT *
        FROM article
    </select>
</mapper>

 

반응형
반응형

 

여러 방법이 있는데 내가 아는 방법은 properties, application.yml이다.

1. properties

2. application.yml 

 

properties 파일로 처음에 하려고 했더니 안먹혀서 우클릭 - convert to application.yml 

 

-------------------------------------------------------

 

spring:

  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp

  datasource:
    driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
    url: jdbc:log4jdbc:mysql://127.0.0.1:3306/프로젝트 이름?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=Asia/Seoul&useOldAliasMetadataBehavior=true&zeroDateTimeNehavior=convertToNull
    username: DB 아이디
    password: DB 비밀번호

 

-------------------------------------------------------

검은 글씨가 맞게 수정해야 할 부분

 

// JSP 경로 세팅 (prefix, suffix 안적어도 자동으로 컨트롤러에서 인식)

// DB 연결

반응형
반응형

1. commit / push 

 

최초 한번

git config --global user.name "ID 적기"

git config --global user.email "email적기"

 

프로젝트마다 한번

git init

git remote add origin https://github.com/~~~~~(repo url 붙여넣기)

 

푸시할 때마다 한번

git pull origin master

git add .

git commit -m "커밋 메시지 작성"

git push origin master

 

2. PULL

 

가져오는 것 최초

 

-폴더 생성

 

git bash here

 

git init

git remote add origin https://github.com/~~~~~(repo url 붙여넣기)

 

git pull origin master 

 

 

3. 커밋 메시지 수정

 

//push 하기 전 커밋 메시지 수정!!!

 

git commit --amend

 

커밋을 수정할 수 있는 창이 뜸

수정 완료한 후 esc -> :wq

 

4. 폴더 및 파일 삭제

 

git rm --cached -r 폴더명

git rm --cached -r 파일명

 

git commit -m "커밋 메시지 작성"

 

git push -u origin master

 

반응형

'GIT' 카테고리의 다른 글

[GIT/GITHUB] 깃허브 특정 커밋으로 돌아가기 (과거 여행)  (0) 2021.05.30
반응형

다른 분들이 아주 잘 정리 해놓았기 때문에 나는 못찾아서 당황했던 일부만 작성하겠음

 

1. WEB, JSP 파일 안될 때 / Preferences에서 WEB, JSP 없을 때

 

help - eclipse marketplace > java and web 검색

 

별 다른 선택없이 next, accept, finish만으로 설치함

설치 후, STS 다시 시작 필요

 

 

2. UTF-8 설정

JSP, XML, HTML, CSS, WORKSPACE 모두 UTF-8 설정

 

3. Font and Color 설정 

 

나눔고딕코딩과 같은 코딩 전용 글꼴 (갠취) 14sizes 이상 설정

눈이 편-안

 

4. Emmet 설치 및 설정

 

1) help - install new software > add > Emment 

http://download.emmet.io/eclipse/updates/

 

url 넣고 설치

 

2) windows - Preferences - emmet > jsp, jspf 추가 

반응형
반응형

1. JAVA 

JDK

https://www.java.com/en/download/

 

 

2. STS 

https://spring.io/tools

 

3. XAMPPP FOR MYSQL(MARIADB)

 

XAMPP는 X(Cross-flatform), A(Apache), M(MariaDB), P(PHP), P(Perl)의 약자

MYSQL만 필요하므로 나머지는 선택 해제 후 설치

 

 

4. sqlyog community

 

https://github.com/webyog/sqlyog-community/wiki/Downloads

 

webyog/sqlyog-community

Webyog provides monitoring and management tools for open source relational databases. We develop easy-to-use MySQL client tools for performance tuning and database management. Webyog's solution...

github.com

 

반응형