앱)java spring에서 web page간의 연동처리

Posted by HULIA(휴리아)
2018. 11. 14. 20:13 백엔드개발/자바스프링
웹페이지 -> java spring
@RequestMapping(value="/example/request", method=RequestMethod.POST)
파라미터기본(HttpServletRequest 와 HttpServletResponse)

특별파라미터추가
form의 name으로 구성된 VO를 만들면 편하게 진행가능하다
@ModelAttribute 이용해서 해당VO를 파라미터에 추가하면 해당 객체에 값이 자동으로 들어가게 된다
 



java spring -> 웹페이지
1)값만 넘길때
리턴값설정 @ResponseBody String
원하는 결과값을 String객체에 담아서 리턴하면 됨

2)페이지 이동을 할때
리턴값설정 ModelAndView
ModelAndView 객체생성하여서
setViewName("example/intro");

3)페이지 이동을 하면서 여러가지 값을 같이 넘길때
리턴값설정 ModelAndView
ModelAndView 객체생성하여서
setViewName("example/intro");
addObject("넘길값의key",넘길값);
addObject("넘길값의key",넘길값);
addObject("넘길값의key",넘길값);
addObject("넘길값의key",넘길값);
addObject("넘길값의key",넘길값);

앱)java spring application config properties 방식

Posted by HULIA(휴리아)
2018. 11. 14. 19:47 백엔드개발/자바스프링
*.java
@Value("#{api['server.brCode']}")
private String api


*.properties
server.brCode=KKKK


applicationContext.xml
xmlns:utill="http:www.springframework.org/schema/util"
http:www.springframework.org/schema/util/spring-util.xsd"


<util:properites id="api" location="file:${home.dir}/api${server.type}.properties />

앱)java spring application Config xml방식

Posted by HULIA(휴리아)
2018. 11. 14. 19:45 백엔드개발/자바스프링
applicationContext.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
               <list>
                      <value>file:${home.dir}/applicationConfig${server.type}.xml</value>
               </list>
     </property>
</bean>

<bean id="CommConfig" class="util.CommConfig">
     <property name="keytest" value=${keytest}" />
     <property name="keytest" value=${keytest}" />
     <property name="keytest" value=${keytest}" />
     <property name="keytest" value=${keytest}" />
     <property name="keytest" value=${keytest}" />
     <property name="keytest" value=${keytest}" />
</bean>

applicationConfig{DEV/STG/PRD}.xml
<?xml version="1.0" encoding="UTF-8"?>
<properties>
           <comment> sample</comment>
       <entry key="keytest">keyvalue</entry>
       <entry key="keytest">keyvalue</entry>
       <entry key="keytest">keyvalue</entry>
       <entry key="keytest">keyvalue</entry>
       <entry key="keytest">keyvalue</entry>
</properties>


CommConfig.java
public class CommConfig{

    private static String keytest;
    private static String keytest;
    private static String keytest;
    private static String keytest;
    private static String keytest;
    private static String keytest;
    private static String keytest;
    private static String keytest;
}

앱)대량호출 방어로직 및 checkusersession

Posted by HULIA(휴리아)
2018. 11. 14. 19:21 백엔드개발/자바스프링
public static void checkUserSession(HttpServletRequest request, HttpServletResponse response){
boolean isLogin = false;
HttpSession session = request.getSession();
if(session != null){
   UserInfoVO user = (UserInfoVO)session.getAttribute("USERINFO");
     if(user!= null && user.getUserID() != null){
        isLogin = true;
      }
      
      //대량 호출 방어 로직
      @SupressWarnings("unchecked")
       Map<String, Object> map = (Map<String, Object>) session.getAttribute(session.getId());
        if(map == null){
map = new HashMap<String, Object>();
map.put("rat", System.currentTimeMillis());
map.put("rac",1);
session.setAttribute(session.getId(), map);

          }else{

//최근 호출 시간 (rat)와 최근 연속호출 count(rac)를 가져온다
long recentAccessTime = (Long) map.get("rat");//recent access time
int accessCount = (Integer) map.get("rac"); //recent access count
int tooManyAccessCnt = Integer.parseInt(ComConfig.getAccessCount());

//연속 호출 건수가 임계치를 넘었다면 세션을 Invalid
if(accessCount >= tooManyAccessCnt) {
logger("to many access, redirect to login page");
session.setAttribute(session.getId(), null);
try{
      response.sendRedirect(CommConfig.getBaseUrl() + request.getContextPath() + "login/intro.do");
 return;
} catch(){
}
}

if( System.currentTimeMillis() - recentAccessTime <= 1000) { //1초안에
accessCount++;
}else{
accountCount =1;
map.put("rat",System.currentTimeMillis());
}
map.put("rac",accessCount);
session.setAttribute(session.getId(), amp);
  }
    //대량호출 방어
}
if( !isLogin){
   try{
         if(request.getHeader("AJAX") != null && request.getHeader("AJAX").equals("true")){
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
}else{
      response.sendRedirect(CommConfig.getBaseUrl() + request.getContextPath() + "/login/intro.do");
}
   }catch(){
}

}



}

차집합 쿼리 만드는 방법

Posted by HULIA(휴리아)
2018. 11. 14. 18:08 백엔드개발/데이터베이스
SELECT
FROM
A서브쿼리
LEFT JOIN
B서브쿼리
ON절
WHERE절 A.ID IS NULL 이나 B.ID IS NULL로 하면 된다
즉 둘중에 NULL유무로 차집합을 출력한다

앱)mybatis resultMap과 resultType 차이

Posted by HULIA(휴리아)
2018. 11. 14. 17:46 백엔드개발/자바스프링
resultMap 방식

<resultMap id="result" type="XXXVO">
     <result property="id" column="ID" />
     <result property="id" column="ID" />
     <result property="id" column="ID" />
     <result property="id" column="ID" />
     <result property="id" column="ID" />
     <result property="id" column="ID" />
     <result property="id" column="ID" />
</resultMap>

<select id="resultmaptest" parameterType="YYYVO" resultMap="result">
....쿼리....
</select>



resultType방식
<select id="resultTypetest" parameterType="searchVo" resultType="outputVO">
<select id="resultTypetest" parameterType="searchVo" resultType="int">
<select id="resultTypetest" parameterType="searchVo" resultType="String">
<select id="resultTypetest" parameterType="searchVo" resultType="map">
...쿼리...
</select>

앱)select box 선택시에 팝업이 뜨는 로직정리

Posted by HULIA(휴리아)
2018. 11. 14. 17:30 백엔드개발/자바스프링
<c:choose>
   <c:when test="">
        <select id="selStatusCd${lineIndex.index}" onchange="changeStatusCode('${id}', '${status}', 'selStatusCd${lineIndex.index}');" onfocus="beforeStatusCode(this);">
          <option value="">${statuscode}</option>
          <option value="R" <c:if test="${statusCode == 'R'}">selected="selected"</c:if>>Ready</option>
   </select>
   </c:when>
   </c:choose>



var changeParams, beforeValue, beforeSelId;

function beforeStatusCode(obj){
    beforeValue = obj.value;
}

function unchangedStatusCode() {
      $("#"+beforeSelId).val(beforeValue);
}

function changeStatusCode(id, previousStatus, selId){
    changeParams = {
              'id' : id,
              'previousStatus' : previousStatus,
               'statusCode' : $("#"+selId).val()
     };

   beforeSelId = selId;
   var msg = 'Do you confirm to chage the [' + id + '] status ?';
  $('#messageValue1").text(msg);
  $.dimPopup.init();
  $.dimPopup.layerOpen("#confirm_popup);
}


function doChnageStatusCode() {
$.ajax({
url : "<c:url value='/xxx.do' />",
type: 'post',
data : changeParams,
beforeSend : function(xhr) {
      xhr.setRequestHeader("AJAX", "true");
 },
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
success : function(data){
       if(data == "ERROR"){
       }else{
       }
},
error:function(xhr, status, error){
   if(xhr.status == 403){
         location.href="<c:url value="/login/intro.do' />";
}


@RequestMapping(value="xxx", method = RequestMethod.POST)
@ResponseBody
public String xxxx(HttpServletRequest request, HttpServletResponse response, @ModelAttribute xxxVO vo){

result="SUCCESS" or result="ERROR"

return result;

앱)maven관련

Posted by HULIA(휴리아)
2018. 11. 14. 17:08 호스팅_서버_툴/툴
mvn -f ./pom.xml clean install

앱)mysql sequence 쿼리 샘플

Posted by HULIA(휴리아)
2018. 11. 14. 17:00 백엔드개발/자바스프링
<select id="makeSequence" parameterType="map" resultType="String">
   SELECT CONCAT(LPAD(CAST(CAST(RAND()*1000 AS UNSIGNED) AS CHAR), 3, '0'), DATE_FOMAT(NOW(), '%Y%m%d'), "-", 'J', #{XXX}, LPAD(CAST(CAST(RAND()*1000000000 AS UNSIGNED) AS CHAR),8,'0'))
</select>

앱)mybatis config.xml

Posted by HULIA(휴리아)
2018. 11. 14. 16:36 백엔드개발/자바스프링
<?xml version="1.0" encoding="UTF-8">

<cofiguration>
   <settings>
         <setting name="cacheEnabled" value="false" />
         <setting name="useGeneratedKeys" value="true" />
         <setting name="defaultExecutorType" value="REUSE" />
         <setting name="defaultStatementTimeout" value="3480" /><!-- sql timeout(58 minutes) -->
  </settings>

  <typeAliases>
      <typeAlias alias="xxxVO" type="com.example.xxxVO />
      <typeAlias alias="xxxVO" type="com.example.xxxVO />
      <typeAlias alias="xxxVO" type="com.example.xxxVO />
      <typeAlias alias="xxxVO" type="com.example.xxxVO />
  </typeAliases>

</configuration>