写着玩的

来源:互联网 发布:好看的运动鞋 知乎 编辑:程序博客网 时间:2024/05/27 03:29

平常我们使用main方法,获取spring依赖注入

public static void main(String[] args) {ApplicationContext ac=new ClassPathXmlApplicationContext("classpath:applicationContext-commons.xml");AnswerService as=(AnswerService) ac.getBean("answerService");//增加//saveFaq(as,130);//删除//delFaq(as,131);//查询getAllAnswer(as,3);}    private static void saveFaq(AnswerService as,int questionId) {        Answer an=new Answer();            an.setUserid(1);            an.setQuestionId(questionId);            an.setAnswer("关机重启啊!");            an.setCreatetime(new Date());                    try {            as.saveAnswer(an);            System.out.println("回答成功");        } catch (Exception e) {            e.printStackTrace();            System.out.println("回答不成功");        }    }    private static void delFaq(AnswerService as,int questionId) {        try {            as.removeAnswer(questionId);            System.out.println("删除成功");        } catch (Exception e) {            e.printStackTrace();            System.out.println("删除不成功");        }    }        private static void getAllAnswer(AnswerService as,int questionId) {        List<Answer> list = (List<Answer>)as.getAllAnswer(questionId);        for(int i=0;i<list.size();i++){            System.out.println(list.get(i).getId()+" "+list.get(i).getAnswer()+" "+list.get(i).getQuestionId()+" ");        }    }
获取系统相关信息
public static void main(String[] args) {Properties props = System.getProperties(); //获得系统属性集  String osName = props.getProperty("os.name"); //操作系统名称  String osArch = props.getProperty("os.arch"); //操作系统构架  String osVersion = props.getProperty("os.version"); //操作系统版本int CPU = Runtime.getRuntime().availableProcessors();//CPU内核数String javaVendor = props.getProperty("java.vendor");//Java 运行时环境供应商String javaVersion = props.getProperty("java.version");//Java 运行时环境版本long freeMemory = Runtime.getRuntime().freeMemory();//内存使用情況:(单位MB)long totalMemory = Runtime.getRuntime().totalMemory();//可使用内存(已分配)long maxMemory = Runtime.getRuntime().maxMemory();//最大可使用内存System.out.println();}




原创粉丝点击