网站开发_springboot
- 网站介绍
- 涉及到的相关知识点
- 网站源码
- 网站介绍
做一个产品展示类的网站,涉及到的技术springboot、vue、redis
网站的样子不是很好看,界面自己调整
http://39.105.69.201:8080/xinhua/medicinal/list
后台界面:
- 涉及到的相关知识点
关于Vue的用法
var vm=new Vue({
el:“#app”, 你要渲染的位置
data:{
lis:[], //空的列表
med:{}, //对象的类型
word:'' , //字符的类型
count: 0
},
mounted:function(){
//相当于初始化,加载只调用一次,例如初始化调用sumtest
this.sumtest(1,2)
},
methods:{
// 定义一些函数,以逗号分隔,可以在前端以@click(或者v-on:click)调用这些函数,
//但是调用的前提是调用必须在#app的范围内
sumtest:function(a,b){
vm.count=a+b;
},
wor:function(){
vm.word="hi !";
}
}
})
mybatis和jpa的选择
mybatis更灵活,旧项目用的更多,但是jpa使用更简单
public interface UserDao extends JpaRepository<User,Integer> {
User findByUsername(String username);
}
自定义异常
你可以自定义一些message信息,定义空的异常一般用于异常捕获
public class ErrorException extends RuntimeException { }
异常捕获
捕获此异常,重定向到登陆的方法
@ControllerAdvice
public class ExceptionHandle {
@ExceptionHandler(value = ErrorException.class)
public ModelAndView handle(){
return new ModelAndView("redirect:/".concat("auth/p_auth"));
}
Aop的使用
面向切面编程,代码中常用于日志或者登陆部分,设置切入点,在切点前验证用户是否登陆
@Aspect
@Component
public class Authorize {
@Pointcut("execution(public * com.happy.xinhua.controller.BackController.*(..))")
public void login(){};
@Before("login()")
public void dologin(){
ServletRequestAttributes attributes =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request= attributes.getRequest();
Cookie c= CookieUtils.getCookie("smile",request);
if(c==null){
throw new ErrorException();
}
}
}
redis缓存
要引入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
启动类上加注解@EnableCaching
使用缓存注解,但是缓存对象都要实例化 implements Serializable
规则见:https://blog.csdn.net/My_blankness/article/details/80988308
使用注解就可以
@Cacheable(cacheNames = "company", key="#root.methodName")
- 网站源码
springmvc+mybatis :https://github.com/smiledip/xinhua/tree/master/springmvc
springboot+jps: 链接:https://pan.baidu.com/s/1TR3-BSO0bDbD_JfVDFwdtw 提取码:wgr9