网站开发
电商类型的特征:
访问量大
数据量大
并发高,实战性强
业务复杂性,技术性
支付安全
(B2C)开发技术:
IDEA:
JDK
Maven
- settings.xml
- <mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
设置国内maven源
每个项目都要设置Maven,否则每次都会下载
Demo:
-
1、新建Maven项目
-
2、在新建的Maven项目基础上,新建Model,选择SpringBoot,并勾选相应服务
-
3、编辑Model中的Resource中的application.properties
-
server.port=8080
- 设置端口
-
注意:
- 若编辑无提示,则点击右侧Maven并刷新
-
-
4、Java逻辑:
package com.example.demo0105;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class IndexController {
@RequestMapping("index")
@ResponseBody //返回json字符串
public String index() {
return "Hello idea springboot";
}
;
}
-
5、运行访问:
- http://localhost:8080/index
Git的配置:
-
1、Git上创建项目,下载到本地:
通用Mapper
可以将单表的增删改查操作省去
pom.xml(导入依赖)
tk.mybatis mapper-spring-boot-starter 1.2.3 org.springframework.boot spring-boot-starter-jdbc使用通用Mapper注意:
-
1、需要继承Mapper
-
Mapper接口继承:
-
效果:
-
-
2、Bean类需要添加注解
-
3、使用通用Mapper时,需要使用通用Mapper的扫描器
-
启动报错:
-
错误:
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
-
解决:
-
application.properties
- #解决通用Mapper报错
mapper.identity=MYSQL
- #解决通用Mapper报错
-
-
-
设置个性化查询:
-
通过ID查询:
-
方法1:
-
-
@Override
public List<UmsMemberReceiveAddress> getReceiveAddressByMemberId(String memberId) {
//ByExample()根据外键查询
//设置泛型
Example e=new Example(UmsMemberReceiveAddress.class);
//根据什么规则去查询
e.createCriteria().andEqualTo("memberId","memberId");
List<UmsMemberReceiveAddress> umsMemberReceiveAddressList=umsMemberReceiveAddressMapper.selectByExample(e);
return umsMemberReceiveAddressList;
}
}
- 方法2:
- UmsMemberReceiveAddress umsMemberReceiveAddress = new UmsMemberReceiveAddress();
umsMemberReceiveAddress.setMemberId(memberId);
List<UmsMemberReceiveAddress> umsMemberReceiveAddressList = umsMemberReceiveAddressMapper.selectByExample(umsMemberReceiveAddress);
return umsMemberReceiveAddressList;
- 纠正
- UmsMemberReceiveAddress umsMemberReceiveAddress = new UmsMemberReceiveAddress();
umsMemberReceiveAddress.setMemberId(memberId);
// List<UmsMemberReceiveAddress> umsMemberReceiveAddressList = umsMemberReceiveAddressMapper.selectByExample(umsMemberReceiveAddress);
List<UmsMemberReceiveAddress> umsMemberReceiveAddressList = umsMemberReceiveAddressMapper.select(umsMemberReceiveAddress);
return umsMemberReceiveAddressList;
-
IDEA快捷键:
-
Ctrl+Alt+v
- 快速本地变量
-
Ctrl+V
- 查看最近操作文件
-
-
设置日记级别:
-
application.properties
-
#设置日志级别
logging.level.root=-
info
- 能不打印就不打印
-
debug
- 执行过程都打印
-
-
-
域名的配置:
步骤一(自定义域名):
-
C:\Windows\System32\drivers\etc\hosts
- 127.0.0.1 localhost user.gmall.com cart.gmall.com manage.gmall.com www.gmall.com
-
刷新本地DNS:
- ipconfig /flushdns
-
效果:
- http://user.gmall.com:8080/index
步骤二(隐藏端口):
-
Nginx:
-
D:\nginx\conf\nginx.conf
- upstream user.gmall.com{
server 127.0.0.1:8080;
- upstream user.gmall.com{
-
}
server {
listen 80;
server_name user.gmall.com;
location / {
proxy_pass http://user.gmall.com;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
}
}
-
启动Nginx:
- 目录下(start nginx)
-
效果:
- http://user.gmall.com/index
User管理项目
1、新建model,选择springweb、mysql驱动、jdbc、mybatis
-
spring boot配置文件
-
application.properties
-
#服务端口号
server.port=8080
#JDBC配置
#数据库用户名
spring.datasource.username=root
#数据库密码
spring.datasource.password=123456
#数据库连接
spring.datasource.url=jdbc:mysql://localhost:3306/gmall_study?characterEncoding=UTF-8#Mybatis配置
-
-
#mapper.xml文件存放地址(class:mapper表示读编译路径下所有以Mapper.xml结尾的文件)
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
#数据库下划线转java驼峰命名
mybatis.configuration.map-underscore-to-camel-case=true
- resource文件下下新建mapper文件夹
2、编写controller、service
-
bean
-
controller
- @Controller
public class UserController {
- @Controller
@Autowired
UserService userService;
@RequestMapping("index")
@ResponseBody
public String index() {
return "hello user";
}
- mapper
- service
- impl
- @Service
public class UserServiceImpl implements UserService {
@Autowired
UserMapper userMapper;
}
- GmallUserApplication.java
- @SpringBootApplication
@MapperScan(basePackages = “com.atguigu.gmall.user.mapper”) //扫描mapper
public class GmallUserApplication {
public static void main(String[] args) {
SpringApplication.run(GmallUserApplication.class, args);
}
}
3、编写bean映射类,映射数据库#表
4、编写具体功能
注意:
-
自动导包设置:
-
IDAE@Autowired自动导包误报:
-
IDEA书写mysql提示:
-
注意:
-
报错:
- Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually.
-
解决:
- set global time_zone = ‘+8:00’;
-
-