DateFormats 추가

master
mjkhan21 1 year ago
parent 73af094530
commit 389cca93c6

@ -0,0 +1,3 @@
package cokr.xit.foundation.component;
public abstract class AbstractBean extends ManagedComponent {}

@ -19,6 +19,7 @@ import cokr.xit.foundation.Assert;
import cokr.xit.foundation.Log; import cokr.xit.foundation.Log;
import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.util.DateFormats;
/**DAO(Data Access Object) . /**DAO(Data Access Object) .
* @author mjkhan * @author mjkhan
@ -30,6 +31,8 @@ public abstract class AbstractDao extends EgovAbstractMapper {
/** 메시지 소스 */ /** 메시지 소스 */
@Resource(name="messageSource") @Resource(name="messageSource")
protected MessageSource messages; protected MessageSource messages;
/** 날짜 포맷 모음 */
protected DateFormats dateFormats = new DateFormats();
/** 로그이름 */ /** 로그이름 */
private String logName; private String logName;
/** SQL mapper 네임스페이스 */ /** SQL mapper 네임스페이스 */

@ -13,6 +13,7 @@ import cokr.xit.foundation.ApplicationException;
import cokr.xit.foundation.Assert; import cokr.xit.foundation.Assert;
import cokr.xit.foundation.Log; import cokr.xit.foundation.Log;
import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.util.DateFormats;
/** /**
* <p> .<br /> * <p> .<br />
@ -38,6 +39,8 @@ public abstract class AbstractServiceBean extends EgovAbstractServiceImpl {
/** 메시지 소스 */ /** 메시지 소스 */
@Resource(name="messageSource") @Resource(name="messageSource")
protected MessageSource messages; protected MessageSource messages;
/** 날짜 포맷 모음 */
protected DateFormats dateFormats = new DateFormats();
/** 로그이름 */ /** 로그이름 */
private String logName; private String logName;

@ -0,0 +1,68 @@
package cokr.xit.foundation.component;
import javax.annotation.Resource;
import org.egovframe.rte.fdl.property.EgovPropertyService;
import org.springframework.context.MessageSource;
import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.Access;
import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.util.DateFormats;
/**spring framework .
* <p>ManagedComponent
* <ul><li>{@link #currentAccess() }</li>
* <li>{@link #currentUser() }</li>
* <li>{@link #properties }</li>
* <li>{@link #message(String, String...) }</li>
* </ul>
* .
* <p>ManagedComponent ' ' + 'Bean' .<br />
* , @Component .<br />
* .
* <pre> package cokr.xit.example.business.service.bean;
* {@code @Component("businessBean")}
* public class BusinessBean extends ManagedComponent {
* ...
* }</pre>
* <p> @Resource .
* <pre><code> @Resource(name = "businessBean")
* BusinessBean businessBean;</code></pre>
*/
public class ManagedComponent extends AbstractComponent {
/** 프로퍼티 서비스 */
@Resource(name="propertyService")
protected EgovPropertyService properties;
/** 메시지 소스 */
@Resource(name="messageSource")
protected MessageSource messages;
/** 날짜 포맷 모음 */
protected DateFormats dateFormats = new DateFormats();
/** .
* @param <T>
* @return
*/
@Override
protected <T extends UserInfo> T currentUser() {
return UserInfo.current();
}
/** .
* @return
*/
protected static Access currentAccess() {
return Access.current();
}
/** key args .
* @param key key
* @param args
* @return
*/
@Override
protected String message(String key, String... args) {
return messages.getMessage(key, ifEmpty(args, () -> null), "", currentAccess().getLocale());
}
}

@ -9,15 +9,15 @@ import cokr.xit.foundation.Assert;
public class DateFormats { public class DateFormats {
private static final HashMap<String, SimpleDateFormat> dateFormats = new HashMap<>(); private static final HashMap<String, SimpleDateFormat> dateFormats = new HashMap<>();
public SimpleDateFormat dateFormat(String pattern) {
return dateFormats.computeIfAbsent(pattern, key -> new SimpleDateFormat(key));
}
public String format(String pattern, Date date) { public String format(String pattern, Date date) {
if (date == null) return ""; if (date == null) return "";
return dateFormat(pattern).format(date); return dateFormat(pattern).format(date);
} }
private SimpleDateFormat dateFormat(String pattern) {
return dateFormats.computeIfAbsent(pattern, key -> new SimpleDateFormat(key));
}
public Date parse(String pattern, String str) { public Date parse(String pattern, String str) {
if (Assert.isEmpty(str)) return null; if (Assert.isEmpty(str)) return null;

@ -30,7 +30,7 @@ public class ExceptionController extends AbstractController {
protected ModelAndView toErrorPage(HttpServletRequest hreq, Object status, String msgKey) { protected ModelAndView toErrorPage(HttpServletRequest hreq, Object status, String msgKey) {
return new ModelAndView("error/errorPage") return new ModelAndView("error/errorPage")
.addObject("json", ajaxRequest()) .addObject("json", ajaxRequest() || jsonResponse())
.addObject("path", getAction(hreq)) .addObject("path", getAction(hreq))
.addObject("failed", true) .addObject("failed", true)
.addObject("status", status) .addObject("status", status)

Loading…
Cancel
Save