본문 바로가기
Back-End/Spring Boot

Spring Boot - 서버

by 코젼 2022. 8. 31.
728x90
반응형


◾ 파일 추가

package com.moble.dev1.test;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
	@RequestMapping("/")
	public String test() {
		return "문자열 반환";
	}
}

create database mydb default character set utf8 collate utf8_general_ci;
usd mydb;

com_DDL_mysql.sql
0.12MB
com_DML_mysql.sql
0.21MB

GRANT ALL PRIVILEGES ON *.* TO 'comp'@'%' IDENTIFIED BY '1234';
FLUSH PRIVILEGES;

egov_mysql_comment.sql
0.23MB

컬럼 명칭을 가져온다.

Getter, Setter, toString

package com.moble.dev1.base.vo;

import java.sql.Timestamp;

public class ComtccmmncodeVo {
	private String codeId;
	private String codeIdNm;
	private String codeIdDc;
	private String useAt;
	private String clCode;
	private Timestamp frstRegistPnttm;
	private String frstRegisterId;
	private Timestamp lastUpdtPnttm;
	private String lastUpdusrId;

	public String getCodeId() {
		return codeId;
	}

	public void setCodeId(String codeId) {
		this.codeId = codeId;
	}

	public String getCodeIdNm() {
		return codeIdNm;
	}

	public void setCodeIdNm(String codeIdNm) {
		this.codeIdNm = codeIdNm;
	}

	public String getCodeIdDc() {
		return codeIdDc;
	}

	public void setCodeIdDc(String codeIdDc) {
		this.codeIdDc = codeIdDc;
	}

	public String getUseAt() {
		return useAt;
	}

	public void setUseAt(String useAt) {
		this.useAt = useAt;
	}

	public String getClCode() {
		return clCode;
	}

	public void setClCode(String clCode) {
		this.clCode = clCode;
	}

	public Timestamp getFrstRegistPnttm() {
		return frstRegistPnttm;
	}

	public void setFrstRegistPnttm(Timestamp frstRegistPnttm) {
		this.frstRegistPnttm = frstRegistPnttm;
	}

	public String getFrstRegisterId() {
		return frstRegisterId;
	}

	public void setFrstRegisterId(String frstRegisterId) {
		this.frstRegisterId = frstRegisterId;
	}

	public Timestamp getLastUpdtPnttm() {
		return lastUpdtPnttm;
	}

	public void setLastUpdtPnttm(Timestamp lastUpdtPnttm) {
		this.lastUpdtPnttm = lastUpdtPnttm;
	}

	public String getLastUpdusrId() {
		return lastUpdusrId;
	}

	public void setLastUpdusrId(String lastUpdusrId) {
		this.lastUpdusrId = lastUpdusrId;
	}

	@Override
	public String toString() {
		return "ComtccmmncodeVo [codeId=" + codeId + ", codeIdNm=" + codeIdNm + ", codeIdDc=" + codeIdDc + ", useAt="
				+ useAt + ", clCode=" + clCode + ", frstRegistPnttm=" + frstRegistPnttm + ", frstRegisterId="
				+ frstRegisterId + ", lastUpdtPnttm=" + lastUpdtPnttm + ", lastUpdusrId=" + lastUpdusrId + "]";
	}

}

 

USE mydb;
CREATE USER 'comp'@'%' IDENTIFIED BY '1234' PASSWORD EXPIRE NEVER;
GRANT ALL PRIVILEGES ON *.* TO 'comp'@'%';
flush privileges;

package com.moble.dev1.base.service;

import java.util.List;
import java.util.Map;

import com.moble.dev1.base.vo.ComtccmmncodeVo;

public interface IComtccmmncodeService {
	public List<ComtccmmncodeVo> list();
	public ComtccmmncodeVo view(String name);
	public int write(Map<String, String> map);
	public int delete(String name);
	public int count();
}

package com.moble.dev1.base.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.moble.dev1.base.dao.IComtccmmncodeDao;
import com.moble.dev1.base.vo.ComtccmmncodeVo;

@Service
public class ComtccmmncodeServiceImpl implements IComtccmmncodeService {
	@Autowired
	IComtccmmncodeDao dao;

	@Override
	public List<ComtccmmncodeVo> list() {
		List<ComtccmmncodeVo> list = dao.listDao();
		return list;
	}

	@Override
	public ComtccmmncodeVo view(String name) {
		return dao.viewDao(name);
	}

	@Override
	public int write(Map<String, String> map) {
		int nResult = dao.writeDao(map);
		return nResult;
	}

	@Override
	public int delete(String name) {
		int nResult = dao.deleteDao(name);
		return nResult;
	}

	@Override
	public int count() {
		int nTotalCount = dao.articleCount();
		return nTotalCount;
	}

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.moble.dev1.base.dao.IComtccmmncodeDao">

	<select id="listDao"
		resultType="com.moble.dev1.base.vo.ComtccmmncodeVo">
		select * from comtccmmncode order by CODE_ID desc
	</select>
	<select id="viewDao"
		resultType="com.moble.dev1.base.vo.ComtccmmncodeVo">
		select * from comtccmmncode where CODE_ID_NM = #{0}
	</select>
	<insert id="writeDao" parameterType="java.util.HashMap">
		insert into comtccmmncode
		(CODE_ID, CODE_ID_NM, coutrycode)
		values (sample_seq.nextval, #{item1},
		#{item2})
	</insert>
	<delete id="deleteDao">
		delete from comtccmmncode where CODE_ID_NM = #{_name}
	</delete>

	<select id="articleCount" resultType="_int">
		select count(*) from
		comtccmmncode
	</select>
</mapper>

package com.moble.dev1.base.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.moble.dev1.base.service.ComtccmmncodeServiceImpl;
import com.moble.dev1.base.vo.ComtccmmncodeVo;

@RestController
public class ComtccmmncodeController {
	@Autowired
	ComtccmmncodeServiceImpl comtccmmncodeService;

	@RequestMapping("/")
	public String root() {
		return "문자열 데이터 전달";
	}

	@RequestMapping("/test")
	public ComtccmmncodeVo test(HttpServletRequest httpServletRequest, Model model) {
		ComtccmmncodeVo vo = new ComtccmmncodeVo();
		vo.setCodeIdNm("Test");
		
		int count = comtccmmncodeService.count();
		vo.setCodeId("Code" + count);
		
		return vo;
	}

	@RequestMapping("/list")
	public List<ComtccmmncodeVo> list(HttpServletRequest httpServletRequest, Model model) {
		List<ComtccmmncodeVo> list1 = comtccmmncodeService.list();
		return list1;
	}

	@RequestMapping("/view")
	public ComtccmmncodeVo view(ComtccmmncodeVo vo, Model model) {
		return vo;
	}

	@RequestMapping("/detail/{name}/{code}")
	public String detail(@PathVariable String code, @PathVariable String name, Model model) {
		return name + "/" + code;
	}
}

728x90
반응형

댓글