发表于: 2017-12-07 23:57:17
2 728
今天完成的任务:
代码部署到远程服务器上,并通过mvn 直接test mvn直接调用main 方法cd 到项目目录下,需要当前目录下的pom文件,否则报错
mvn compile exec:java -Dexec.mainClass="com.bbq.services.StudentService"
mvn test
与在idea环境差别不大,不过mvn 里的镜像设置成阿里云的要快些的
try cache 部分
在dao层直接在函数定义处 throws Exception,然后services 也直接throws,最后在main里的来处理的
import com.bbq.beans.Student;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.concurrent.ExecutionException;
@Repository
public class StudentDao {
@Autowired
private SqlSessionTemplate sessionTemplate;
public List<Student> getStudentByName(final String name) throws Exception{
return sessionTemplate.selectList("com.bbq.dao.mapper.StudentMapper.getByName", name);
}
public Student getStudentById(final int id) throws Exception {
return sessionTemplate.selectOne("com.bbq.dao.mapper.StudentMapper.getById", id);
}
}
@Service
public class StudentService {
@Autowired
private StudentDao studentDao;
public void getStudentByName(String name) throws Exception{
List<Student> sts = studentDao.getStudentByName(name);
System.out.println(sts.size());
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
BeanFactory beanFactory = (BeanFactory) context;
StudentService ss = beanFactory.getBean("studentService", StudentService.class);
try {
ss.getStudentByName("朱浩");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
评论